getDate in function generates error 208

  • Hi can anybody tell me why I get this message and how to solve this?

    I am logged in as Sa and

    the following works just fine:

    select dbo.getDate()

     

    when I place this in a function:

     

    create function test1()

    returns datetime

    as

        begin

                return dbo.getDate()

        end

     

    GO

     

    It compiles ok  bud When I do this:

     

    select dbo.test1()

     

    I get the following error:

     

    Server: Msg 208, Level 16, State 1, Procedure test1, Line 5

    Inval,id object name 'dbo.getDate'.

     

    thanks

  • Where and when "select dbo.getDate()" works fine?

    It does not work in my SQL2000.

    _____________
    Code for TallyGenerator

  • when using Query analyzer i can just type

    select getDate()

     (bud not with the dbo. prefix sorry )

     

    I just find the answer, wel someone else actualy: return non-deterministic values are not allowed

    here http://www.databasejournal.com/features/mssql/article.php/3348181 you can read all about is

    thanks for your queick replay though 

     

  • Actually, not quite true... you can "return [apparently] non-deterministic values" if you trick the heck out of it...

    First, create a view that looks something like this...

     CREATE VIEW GetNow

         AS

     SELECT GETDATE() AS Now

    Then, create a function similar to what you did but point it to the view...

     CREATE FUNCTION Test1()

    RETURNS DATETIME

         AS

      BEGIN

            RETURN (SELECT Now FROM dbo.GetNow)

        END

    Then, you can do this with no error...

    SELECT dbo.Test1()

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • That’s a good idea thanks.

    This will help a lot keeping my code clean!

     

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

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