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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple GetDate question

Status
Not open for further replies.

Baesucks

Programmer
Mar 10, 2008
37
US
I get an error when I try to set the current date to a datetime variable using these statements...

DECLARE @LatestDate Datetime
Set @LatestDate = SELECT GETDATE() AS Expr1

What am I doing wrong?
 
DECLARE @LatestDate Datetime
SELECT @LatestDate = GETDATE()
 
I still get an error "Invalid use of getdate() within a function". I should have mentioned this is within a Scalar Function I'm building. Is there a problem with using built-in functions within user-defined functions?
 
When I do something like this, I pass a date into the function.
 
You can't do that.
Books Online said:
Built-in nondeterministic functions are not allowed in the body of user-defined functions; they are as follows:

@@CONNECTIONS
@@TOTAL_ERRORS
@@CPU_BUSY
@@TOTAL_READ
@@IDLE
@@TOTAL_WRITE
@@IO_BUSY
GETDATE
@@MAX_CONNECTIONS
GETUTCDATE
@@PACK_RECEIVED
NEWID
@@PACK_SENT
RAND
@@PACKET_ERRORS
TEXTPTR
@@TIMETICKS
As Riverguy said pass it in as a parameter.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top