Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Test value of date as passed as parm

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-07-16 : 16:39:40
How do I test on date value passed as parm (whether it is empy or blank)?

CREATE PROCEDURE sp_ProductionInquiry  

@JobNumber int,
@DateFrom datetime,

IF @DateFrom = 0 BEGIN
SELECT job_date .........
END
ELSE
BEGIN
SELECT job_date .....

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-16 : 16:48:34
Since it is declared as DATETIME it always has a datetime value.
The only other value possible is NULL.

IF @DateFrom IS NULL BEGIN
SELECT job_date .........
END
ELSE
BEGIN
SELECT job_date .....
WHERE SomeDateColumn >= @DateFrom



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-07-16 : 19:02:51
Peso, as always, thank you ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-17 : 00:07:26
and IF ELSE can be written as

SELECT job_date .....
WHERE (SomeDateColumn >= @DateFrom
OR @DateFrom IS NULL)
Go to Top of Page
   

- Advertisement -