Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    223

    Unanswered: Cannot use GETDATE ( ) in a function?

    I want to use GETDATE ( ) in a user defined function for date comparing. When I compile the function, got the error:

    Invalid use of 'getdate' within a function.

    How to get the current date in a function? Any suggestion will be appreciated.

    ZYT

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The way that SQL 2000 impliments User Defined Functions (UDFs) requires that the functions be deterministic, in other words that for a given set of function arguments the UDF will always return the same result. GetDate() is non-deterministic because it should return a different value every time it is called. Because of that, you can't call GetDate() within a SQL 2000 UDF, although you can use GetDate() as an argument to one and use that argument any way you see fit.

    -PatP

  3. #3
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    you cannot use a non-deterministic function within a UDF.getdate() is a non deterministic function. So better pass getdate() value as parameter to ur function .There are otherways too.check this link for more details.

    http://www.aspfaq.com/show.asp?id=2439
    Last edited by mallier; 12-22-05 at 10:19.
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •