I have a SP that gives me a lot of hard times.
The sp gets a two parameters @madeByUserId and @reportedByUserId. I want to have something like:
select * from table
where MadeByUserId = @madeByUserId (if(@reportedByUserID != null) and ReportedByUserID = @reportedByUserID)
Basically I want to make a case in the where clause to include another filter condition based of the null/not null state of the @reportedByUserId
Is that possible?
Thanks a lot, Radu
You could use
COALESCE
.This translates to
From MSDN
Try:
Add an if statement
IF (@reportedByUserId IS NOT NULL)
SELECT * FROM table t WHERE t.MadeByUserId = madeByUserId etc
I think this will give you what you're after.