function help -

  • 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

  • sorry for the daft post

    fixed

  • 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

  • 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