本文介紹了如果參數(shù)為空,where 語句中的 TSQL Case的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個給我?guī)砗芏嗬щy的 SP.
I have a SP that gives me a lot of hard times.
sp 得到兩個參數(shù)@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 的空/非空狀態(tài)的過濾條件
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)
這篇關于如果參數(shù)為空,where 語句中的 TSQL Case的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!