本文介紹了如果參數為空,where 語句中的 TSQL Case的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個給我帶來很多困難的 SP.
I have a SP that gives me a lot of hard times.
sp 得到兩個參數@madeByUserId 和@reportedByUserId.我想要類似的東西:
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)
基本上我想在 where 子句中包含另一個基于 @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
這可能嗎?
非常感謝,拉杜
推薦答案
嘗試:
select * from table
where MadeByUserId = @madeByUserId
AND (@reportedByUserID IS null OR ReportedByUserID = @reportedByUserID)
這篇關于如果參數為空,where 語句中的 TSQL Case的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!