October 18, 2010 at 9:48 am
here are the errors i am getting
Msg 102, Level 15, State 1, Procedure fn_DateTime, Line 8
Incorrect syntax near 'oldDate'.
Msg 178, Level 15, State 1, Procedure fn_DateTime, Line 23
A RETURN statement with a return value cannot be used in this context.
here is the function
create function dbo.fn_DateTime(oldDate nvarchar(30))
returns nvarchar(30)
as
begin
declare @ret nvarchar(30)
if len(oldDate) > 1
begin
set @ret = substring(oldDate, 4, 2) + '-' + substring(oldDate, 1, 2) + '-' + substring(oldDate, 7, len(oldDate))
end
else
begin
set @ret = ''
end
return(@ret)
end
can anyone help please
October 18, 2010 at 9:55 am
sorry for the daft post
fixed
October 18, 2010 at 10:08 am
You need to use the '@' symbol to declare the variable you are passing in, then use it again when using that variable in the actual function. Try the code below, it should work successfully.
create function dbo.fn_DateTime(@oldDate nvarchar(30))
returns nvarchar(30)
as
begin
declare @ret nvarchar(30)
if len(@oldDate) > 1
begin
set @ret = substring(@oldDate, 4, 2) + '-' + substring(@oldDate, 1, 2) + '-' + substring(@oldDate, 7, len(@oldDate))
end
else
begin
set @ret = ''
end
return(@ret)
end
October 19, 2010 at 2:28 am
thanka mate, i realised just after i started the thread which is why i added the second post
it had been a long day 🙂
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply