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

GetDate() in Stored Procedure

Status
Not open for further replies.

flanakin

Programmer
Mar 21, 2000
158
US
I have a stored procedure that updates a UpdatedByUserID and UpdateDate columns in a table. For some reason, the user ID is updated, but not the update date. The following SQL is run as DBO:

Code:
[blue]UPDATE[/blue] UserDefinedRows
[blue]SET[/blue]    UpdatedByUserId = [green]@UserID[/green],
       UpdateDate = [blue]GETDATE()[/blue]
[blue]WHERE[/blue]  UserDefinedRowId = [green]@UserDefinedRowId[/green]

What's even worse is, if I execute the stored procedure from Query Analyzer, it works fine. Has anyone seen this before? I'm stumped.

________________________________________
Michael Flanakin
 
It should work no matter how you call the procedure. I have never come across this problem. You can eliminate the updating of the UpdateDate in the SP and use a trigger to update it.

Jim
 
While that SHOULD work, try this and see if there's a difference:
Code:
UPDATE UserDefinedRows
SET    UpdatedByUserId = @UserID
SET    UpdateDate = GETDATE()
WHERE  UserDefinedRowId = @UserDefinedRowId

I removed the comma and added a second SET

-SQLBill


Posting advice: FAQ481-4875
 
This is something else you could try:
Code:
UPDATE UserDefinedRows
SET    UpdatedByUserId = @UserID,
       UpdateDate = (SELECT GETDATE())
WHERE  UserDefinedRowId = @UserDefinedRowId

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top