I want to select rows in a stored procedure depending on the value of an input variable. The variable can be null. What is the best way?
-------------------------------------
Declare @sound int
SET @Sound=NULL
--This does NOT work
select * from tblSpot where Sounding=@sound
--This works, but is not very elegant (I have many variables to check)
select * from tblSpot where Sounding=@sound OR (Sounding IS NULL AND @sound IS NULL)
------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
-------------------------------------
Declare @sound int
SET @Sound=NULL
--This does NOT work
select * from tblSpot where Sounding=@sound
--This works, but is not very elegant (I have many variables to check)
select * from tblSpot where Sounding=@sound OR (Sounding IS NULL AND @sound IS NULL)
------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'