HI,
if I pass fname then query should return only that condition,If null it should return all records.
declare
@fname as nvarchar(10)
set @fname=null
select * from emp where fname=@fname or @fname=null(Expected It will return all records but it returns 0 records)
I tried another approach
declare
@fname as nvarchar(10)
set @fname=''
select * from emp where fname=@fname or @fname=''(It works but it takes lot of time for the query to complete)
In my actual query I have joins.
Kindly Guide me with any other good approach for this type of conditions.
if I pass fname then query should return only that condition,If null it should return all records.
declare
@fname as nvarchar(10)
set @fname=null
select * from emp where fname=@fname or @fname=null(Expected It will return all records but it returns 0 records)
I tried another approach
declare
@fname as nvarchar(10)
set @fname=''
select * from emp where fname=@fname or @fname=''(It works but it takes lot of time for the query to complete)
In my actual query I have joins.
Kindly Guide me with any other good approach for this type of conditions.