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

Stored Procedure Syntax

Status
Not open for further replies.

jw2000

Programmer
Aug 12, 2005
105
0
0
US
Inside my stored procedure, I would like to store the pilotActiveSinceTimestamp into the variable @myActiveSinceTS. If @myActiveSinceTS is null, I would like to update the pilotActiveSinceTimestamp to date(). What is the syntax to do this?

@myActiveSinceTS = select pilotActiveSinceTimestamp from pilot where pilotId = @pilotId ??
 
Hi,
This code will select the time stamp from the database and if it is null assign it to the current date/time.

If I remeber rightly there are cleaner ways to do this, but this is the easiest.

Code:
DECLARE @myActiveSinceTS TIMESTAMP

select @myActiveSinceTS=pilotActiveSinceTimestamp from pilot where pilotId = @pilotId

IF @myActiveSinceTS IS NULL 
BEGIN
 SET @myActiveSinceTS = CONVERT(TIMESTAMP,GETDATE())
END

--Display the Variable
--SELECT @myActiveSinceTS
Thanx!

Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top