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!

datetime > @Variable

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
I am writing a stored procedure where i am passing in a date (although not required). If it is passed it, i want to select all the records with a date greater than that:

Select * from tblName
where column > @DateVariable

How do i check if null is passed in without writing several statements?

(i.e.,)
If (@DateColumn is null)
BEGIN

END
ELSE

 
Code:
Select * from tblName
where column > ISNULL(@DateVariable, '19000101')

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Why don't you always pass it a value (give it a default value of 1/1/1901)?

-- Jason
"It's Just Ones and Zeros
 
O!
I miss that you use Stored procedure.
Then just define it as :
Code:
CREATE PROCEDURE YourNameHere(
       ...
       @DateColumn datetime = '19000101'
       ...
AS
  BEGIN
      ....
      Select * from tblName
      where column > @DateVariable
  END
[code]


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top