March 2, 2007 at 4:09 am
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
March 2, 2007 at 4:32 am
Where and when "select dbo.getDate()" works fine?
It does not work in my SQL2000.
_____________
Code for TallyGenerator
March 2, 2007 at 5:20 am
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
March 2, 2007 at 5:54 am
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
Change is inevitable... Change for the better is not.
March 2, 2007 at 8:34 am
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