Home Forums SQL Server 2008 SQL Server Newbies Dynamic WHERE statement if stored procedure parameter is null RE: Dynamic WHERE statement if stored procedure parameter is null
Steven Willis
SSCrazy Eights
Points: 9893
More actions
July 10, 2013 at 3:38 pm
#1631428
I use this syntax in my where clauses rather than case statements:
WHERE
((@StartDate IS NOT NULL AND StartDate >= @StartDate)
OR
(@StartDate IS NULL))
AND ((@EndDate IS NOT NULL AND EndDate <= @EndDate)
(@EndDate IS NULL))