Sometimes we have to use a parameter that will form the basis of the condition in the Query. For e.g. if the parameter has a value, then we want to use it in the condition, otherwise we want to retrieve all the records. This can be achieved by:
declare @vEname nvarchar(60)
set @vEname = null
Select * from Emp where Ename = isnull(@vEname,Ename)
In the above script, if @vEname has some value, then the query will run based on that condition, otherwise it will run on the condition of "Ename = Ename" column, which will always return true and hence will return all the records.
Happy Coding.!
declare @vEname nvarchar(60)
set @vEname = null
Select * from Emp where Ename = isnull(@vEname,Ename)
In the above script, if @vEname has some value, then the query will run based on that condition, otherwise it will run on the condition of "Ename = Ename" column, which will always return true and hence will return all the records.
Happy Coding.!
Comments