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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Plz suggest where i am wrong

Author  Topic 

Dhanu
Starting Member

3 Posts

Posted - 2008-03-25 : 01:50:34
I am new in sqlserver UDF,
I am written a UDF but it showing error
CREATE FUNCTION udf_DayOfWeek(@dtDate DATETIME)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @rtDayofWeek VARCHAR(10)
SELECT @rtDayofWeek = CASE DATEPART(weekday,@dtDate)
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’
END
RETURN (@rtDayofWeek)
END
GO

Error
Incorrect syntax near '‘'.
Msg 102, Level 15, State 1, Procedure udf_DayOfWeek, Line 16
Incorrect syntax near 'END'.

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 2008-03-25 : 01:59:39
Use Single Quote,
‘Sunday’ should be 'Sunday'
Go to Top of Page

pravin14u
Posting Yak Master

246 Posts

Posted - 2008-03-25 : 02:02:07
Try this,

CREATE FUNCTION udf_DayOfWeek(@dtDate DATETIME)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @rtDayofWeek VARCHAR(10)
SET @rtDayofWeek = CASE DATEPART(weekday,@dtDate)
WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
else 'Saturday'
END
RETURN (@rtDayofWeek)
END
GO

it didnt work initially as it could not recognize your quotes used (i.e)'‘'.
Go to Top of Page

Dhanu
Starting Member

3 Posts

Posted - 2008-03-25 : 02:02:16
quote:
Originally posted by Koji Matsumura

Use Single Quote,
‘Sunday’ should be 'Sunday'



Thnks For your report
Go to Top of Page
   

- Advertisement -