TSQL Case in where statement if parameter is null

前端 未结 4 1216
失恋的感觉
失恋的感觉 2021-02-06 01:09

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          


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 01:47

    Try:

     select * from table
     where MadeByUserId = @madeByUserId 
     AND (@reportedByUserID IS null OR ReportedByUserID = @reportedByUserID)
    

提交回复
热议问题