In my stored procedure, i am having several parameters which in case if one of them is filled some of them will be ignored and vise versa.
create procedure FlightReservations
@resDate date = getdate,
@fromdate date = null,
@todate date = null,
-- few more parameters
if(@fromdate != null)
--it has more inner joins
select * from tbl1 inner join tbl2 on tbl1.id=tbl2.id where tbl1.fromDate=@fromDate
select * from tbl1 inner join tbl2 on tbl1.id=tbl2.id where tbl1.date=@resDate
select * from tbl1 inner join tbl2 on tbl1.id=tbl2.id
Note that checking against null should be used as IS NULL or IS NOT NULL, since NULL is not a value.
This should be what you are looking for
SELECT * FROM tbl1 INNER JOIN tbl2 ON tbl1.id = tbl2.id WHERE (@fromdate IS NOT NULL AND tbl1.fromDate = @fromDate) OR (@fromdate IS NULL AND tbl1.date = @resDate)