Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SilentCodingOne
Starting Member
20 Posts |
Posted - 2008-12-07 : 00:18:17
|
I'm working on a homework problem that requires the creation of a script that determines the integer value of the current day of the week using GETDATE() and DATEPART(). Then using a CASE statement I have to take the integer value of the day of the week and assign it the appropriate character representation of the day. The last step is to use PRINT to show the day of the week. Whenever I run the script I have I get the following error:Msg 156, Level 15, State 1, Line 15Incorrect syntax near the keyword 'PRINT'.Not sure what I'm doing wrong and hoping you guys can help. Here is my code:DECLARE @DayOfWeek INTDECLARE @DayName VARCHAR(10)SET @DayOfWeek = DATEPART(weekday,GETDATE())SELECT @DayName = CASE @DayOfWeek WHEN 1 THEN 'Sunday' WHEN 2 THEN 'Monday' WHEN 3 THEN 'Tuesday' WHEN 4 THEN 'Wednesday' WHEN 5 THEN 'Thursday' WHEN 6 THEN 'Friday' WHEN 7 THEN 'Saturday' PRINT @DayName |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
SilentCodingOne
Starting Member
20 Posts |
Posted - 2008-12-07 : 02:02:59
|
I updated my code to what you recommended. I no longer get the incorrect syntax near PRINT error but now it is saying incorrect syntax near =. If I change CASE @DayOfWeek to just CASE the error goes back to incorrect syntax near PRINTSELECT @DayName = CASE @DayOfWeek WHEN @DayOfWeek = 1 THEN 'Sunday' WHEN @DayOfWeek = 2 THEN 'Monday' WHEN @DayOfWeek = 3 THEN 'Tuesday' WHEN @DayOfWeek = 4 THEN 'Wednesday' WHEN @DayOfWeek = 5 THEN 'Thursday' WHEN @DayOfWeek = 6 THEN 'Friday' WHEN @DayOfWeek = 7 THEN 'Saturday' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-07 : 02:07:19
|
quote: Originally posted by SilentCodingOne I updated my code to what you recommended. I no longer get the incorrect syntax near PRINT error but now it is saying incorrect syntax near =. If I change CASE @DayOfWeek to just CASE the error goes back to incorrect syntax near PRINTSELECT @DayName = CASE @DayOfWeek WHEN @DayOfWeek = 1 THEN 'Sunday' WHEN @DayOfWeek = 2 THEN 'Monday' WHEN @DayOfWeek = 3 THEN 'Tuesday' WHEN @DayOfWeek = 4 THEN 'Wednesday' WHEN @DayOfWeek = 5 THEN 'Thursday' WHEN @DayOfWeek = 6 THEN 'Friday' WHEN @DayOfWeek = 7 THEN 'Saturday'
it should be belowDECLARE @DayOfWeek INTDECLARE @DayName VARCHAR(10)SET @DayOfWeek = DATEPART(weekday,GETDATE())SELECT @DayName = CASE @DayOfWeek WHEN 1 THEN 'Sunday' WHEN 2 THEN 'Monday' WHEN 3 THEN 'Tuesday' WHEN 4 THEN 'Wednesday' WHEN 5 THEN 'Thursday' WHEN 6 THEN 'Friday' WHEN 7 THEN 'Saturday' ENDPRINT @DayName |
|
|
SilentCodingOne
Starting Member
20 Posts |
Posted - 2008-12-07 : 02:08:40
|
Thanks that worked |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-07 : 02:13:51
|
welcome |
|
|
|
|
|