I'm trying to do something very simple here but I keep getting stuck becuase I can't find much on getDate() in the documenation. Where, in the documenation, does it talk about truncating times, adding to times and all that good stuf.
Below is what I'm trying to do here: I have a while loop that adds to the starting hour of 6am 15 min until it gets to like 7pm. I do realize at this point that just adding 15 is suppsed to add 15 days based on what I have read, but I'm getting an error when I parse this and since I can't seem to find the docs I don't know what to do next?
Msg 102, Level 15, State 1, Procedure PopulateDatabase, Line 32
Incorrect syntax near '@.TeeTime'.
set ANSI_NULLSONset QUOTED_IDENTIFIERONGO-- =============================================-- Author:Przemek-- Create date: -- Description:-- =============================================ALTER PROCEDURE [dbo].[PopulateDatabase]-- Add the parameters for the stored procedure hereASdeclare @.CourseIDuniqueIdentifierdeclare @.TeeTimeSlotintdeclare @.TeeTimedateTimeBEGINSET NOCOUNT ON;--Course 1 *******************************************************************INSERT INTOCourse (CourseID,Name, Address, PhoneNumber)VALUES(NewID(),'Prospect Lake','123 Prospect St', 2508129832)SET @.CourseID = (SELECT CourseIDFROM CourseWHERE Name ='Prospect Lake')SET @.TeeTimeSlot = 0SET @.TeeTime ='6:00'WHILE @.TeeTimeSlot < 56BEGIN INSERT INTOSchedule (ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayers)VALUES(NewID(), @.CourseID,getDate(), @.TeeTime, Rand(5))@.TeeTime = @.TeeTime + 1ENDEND
Helloprzemeklach,
the problem should instead be on the next line, where you miss the SET keyword when incrementing @.TeeTime.
Documentation is into the Sql Books Online, that is the local sql server help. As for any other MS technology, you can find all the docs online as well, on the MSDN site. Here is a link:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/startsql/getstart_4fht.asp
HTH. -LV
Thanks, as my luck would have it I just figured this out like 2 min before you answered my post. Thanks for the link to the documentation, just what I was looking for.
I still have one more question. I want the column TeeTime to just store 06:00, 06:15 etc but instead it's filling it with 1900-01-01 06:00:00 etc. I know this is because of the smallDateTime datatype but is there a way to truncate this so the column is just filled with smallDateTime datatype but with just the time. If not, no big deal, I can just get my code to truncate the year/date as I use this data to populate controls.
set ANSI_NULLSONset QUOTED_IDENTIFIERONGO-- =============================================-- Author:Przemek-- Create date: 15 August 2006-- Description:Populates Course and Schedule-- tables with bogus data.-- =============================================ALTER PROCEDURE [dbo].[PopulateDatabase]-- Add the parameters for the stored procedure hereASdeclare @.CourseIDuniqueIdentifierdeclare @.TeeTimeSlotintdeclare @.TeeTimesmallDateTimeBEGINSET NOCOUNT ON;--Course 1 *******************************************************************INSERT INTOCourse (CourseID,Name, Address, PhoneNumber)VALUES(NewID(),'Prospect Lake','123 Prospect St', 2508129832)SET @.CourseID = (SELECT CourseIDFROM CourseWHERE Name ='Prospect Lake')SET @.TeeTimeSlot = 0SET @.TeeTime ='06:00:00'WHILE @.TeeTimeSlot < 56BEGIN INSERT INTOSchedule (ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayers)VALUES(NewID(), @.CourseID,getDate(), @.TeeTime, ((Rand()*5)+1))SET @.TeeTime =DATEADD(minute, 15, @.TeeTime)SET @.TeeTimeSlot = @.TeeTimeSlot + 1ENDEND|||
przemeklach:
> I want the column TeeTime to just store 06:00, 06:15 etc but instead it's filling it with 1900-01-01 06:00:00 etc.
I'm afraid that's it. Both T-Sql and .NET languages don't have a 'time' data type. As you maybe implied, there's the DateTime.ToXYZString methods for handling display.
-LV
No comments:
Post a Comment