Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getdate In user Function

Status
Not open for further replies.

sefafo

Programmer
Aug 28, 2003
36
CO
Hello!! I am traying to do this in a function
declare @CurrentDate datetime
select @CurrentDate=getdate()

but I got this error when compiling:

Servidor: mensaje 443, nivel 16, estado 1, procedimiento fGetRadicationNumber, línea 14
Uso no válido de 'getdate' en una función.

Thanks a lot!
 
Try:
declare @CurrentDate datetime
set @CurrentDate = getdate()

-SQLBill

The Books OnLine suggest that SET be used instead of SELECT.
 
Thanks but No, with Set also fails the compiling
 
udf's must be deterministic which means that you cannot use getdate() within a function.
You can pass it in as a parameter though.

It may appear that you can define a view which returns getdate() and use that in the function but this is just fooling the compiler and can produce incorrect results.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Perhaps you can pass GetDate() to the function as a parameter.

-dave
 
vidru is correct.

You can pass getdate() in but you can't call it with in a user function. All functions called within a user function must be deterministic, in other words if called with the same parameter or without a parameter they must return the same value. Obviously that would not be true of getdate().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top