|
Posted by grant on 01/10/07 04:46
Well, I just downloaded SQL 2005 Express to have a play. Good old Bill
says "up and running in 20 minutes"
Well 5 hrs, 5 reboots and 4 full un-install and re-install later I have
finally got it working. About what I expected really.
Anyway, my question relates to creating user defined functions. I've 10
yrs exp in MS Access and VB, and user ent Manager to create views on
the work server, but havnt done much with functions.
I'm using the Management Studio Express.
I've opened a new view and copied the following sample code but it wont
let me save it.
-------------------------
IF OBJECT_ID(N'dbo.GetWeekDay', N'FN') IS NOT NULL
DROP FUNCTION dbo.GetWeekDay;
GO
CREATE FUNCTION dbo.GetWeekDay -- function name
(@Date datetime) -- input parameter name and data
type
RETURNS int -- return parameter data type
AS
BEGIN -- begin body definition
RETURN DATEPART (weekday, @Date) -- action performed
END;
GO
------------------------------------------
When I try to save it it says
"incorrect syntax near the key work 'IF'
incorrect syntax near 'GO'
CREATE FUNCTION must be the first statement in a query batch
must declair the scalar variable "@Date"
Whats wrong with the syntax???
Thanks in advance
Grant
[Back to original message]
|