GETDATE in function

  • Hi,

    I'm new in SQL, is it not posible to call a GETDATE() in a user defined function

    Thanks!

    Thomas Vanting

  • you cannot use Getdate() in a udf, Look for deterministic functions in bol.

  • However you can provide a parameter in the UDF to submit GETDATE() thru.

  • Okay, thanks

    Thomas Vanting

  • If you need the current date in a UDF you can also fudge it a little bit by performing the following query in the UDF :

        DECLARE @dtDate datetime

        SELECT @dtDate = convert(datetime, convert(varchar(20), last_batch, 101))

        FROM master..sysprocesses

        WHERE spid = @@spid

     

  • The easiest way to use GETDATE() in a UDF is to create a view that calls GETDATE() and use the view in the function.

    Razvan

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply