我有一個情況,如果我傳遞一個引數@param,那么我需要我的where子句是
where field1 = @param
但是,根據@param1的值,where條款可能是
where field1 in (...幾種可能性)
另外,where子句可以是
where field1 is in (...幾種可能性)
or field1 like ...%
因此,根據我傳遞的資訊,where子句可以有多個 "個性"。你如何做到這一點?
我看了一下創建一個字串
@sqlquery = "select whatever from wherever where ..."
然后用sp_executesql執行它,但我仍然不確定到底如何做。這似乎是我需要的方向。
uj5u.com熱心網友回復:
轉換欄位和引數,所以它將是
where @param like '%field1%'
uj5u.com熱心網友回復:
@aaronbertran的博客(KitchenSink)上概述的方法確實解決了我的問題。還有更多復雜的因素,但這已經轉化為所有的因素。 謝謝你的所有建議。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/311081.html
標籤:
