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

Parameter Field

Status
Not open for further replies.
Mar 20, 2009
102
US
I have a parameter @date. I want it to be setup as to where it can accept a date of it one is not passed in, it defaults to getdate(). How can I go about doing that?

Declare @date datetime
Set @date = ?????

Thanks!
 
Code:
IF @Date IS NULL
   SET @DATE = GETDATE()

or if it is in SP
Code:
CREATE PROCEDURE WhatEver (
       @Date datetime = GETDATE(),
...

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Sounds to me like you want it to be an optional parameter. You cannot set an optional parameter to use GetDate(). But... you can set an optional parameter to be NULL and within the stored procedure set it to GetDate(), like this...

Code:
Create Procedure Whatever(@Date DateTime = NULL)
As
SET NOCOUNT ON

Set @Date = Coalesce(@Date, GetDate())

-- Use the @Date parameter

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top