create procedure sp_get_report(@datefrom date=null,@dateto date=null,@customerfrom nvarchar(40)=null,@customerto nvarchar(40)=null,@salesrepfrom nvarchar(40)=null,@salesrepto nvarchar(40)=null)
as
begin
select total from employee where alldate between @datefrom and @dateto
and customer between @customerfrom and @customerto
and sales between @salesrepfrom and @salesrepto
end
go
exec sp_get_report '2014-10-01','2014-10-03' -- if i did not pass @customerfrom,@customerto,@salesrepfrom,@salesrepto, i get null. becuase i used optional parameter for condition.
so if any set of between and condition is null, that particular betwenn and should not use.
we need use between and condition whatever is not null only. i guess it could be done using case any other way. but i am in learing process only.
if anyone knows, help me.
Go to the complete details ...