I'm trying to create a function to return a customer's age.
for some reason I'm getting "syntax error near as. line 2"
I've tried taking out "as datetime" in header, but get comma syntax error????
here is the code
/*#############################*/
ALTER function "me"."GetAge"
(@in_DOB as datetime,@now as datetime)
returns int
as
begin
DECLARE @age int
IF cast(datepart(m,@now) as int) > cast(datepart(m,@in_DOB) as int)
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int)
else
IF cast(datepart(m,@now) as int) = cast(datepart(m,@in_DOB) as int)
IF datepart(d,@now) >= datepart(d,@in_DOB)
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int)
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int) -1
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int) - 1
RETURN @age
end
/*####################*/
for some reason I'm getting "syntax error near as. line 2"
I've tried taking out "as datetime" in header, but get comma syntax error????
here is the code
/*#############################*/
ALTER function "me"."GetAge"
(@in_DOB as datetime,@now as datetime)
returns int
as
begin
DECLARE @age int
IF cast(datepart(m,@now) as int) > cast(datepart(m,@in_DOB) as int)
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int)
else
IF cast(datepart(m,@now) as int) = cast(datepart(m,@in_DOB) as int)
IF datepart(d,@now) >= datepart(d,@in_DOB)
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int)
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int) -1
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,@now) as int) - 1
RETURN @age
end
/*####################*/