我需要查詢一些數據。這裏是我構建的查詢,但這對我來說並不合適。對於這個例子我使用AdventureWorks數據庫。帶CASE語句的多個條件
SELECT * FROM [Purchasing].[Vendor] WHERE PurchasingWebServiceURL LIKE
case
// In this case I need all rows to be returned if @url is '' or 'ALL' or NULL
when (@url IS null OR @url = '' OR @url = 'ALL') then ('''%'' AND PurchasingWebServiceURL IS NULL')
//I need all records which are blank here including nulls
when (@url = 'blank') then (''''' AND PurchasingWebServiceURL IS NULL')
//n this condition I need all record which are not like a particular value
when (@url = 'fail') then ('''%'' AND PurchasingWebServiceURL NOT LIKE ''%treyresearch%''')
//Else Match the records which are `LIKE` the input value
else '%' + @url + '%'
end
這不適合我。如何在同一CASE
的THEN
中有多個條件條款?我該如何做這項工作?
讓我想知道爲什麼我只是通過使用CASE語句來嘗試這樣做。我想我可以用它來構建查詢,因爲我需要。感謝 – pavanred 2010-06-13 19:13:01
It's基本上是:(!!!條件1和條件2和condition3和條件4) 條件1 或條件2 或狀況3 或 沒有問題=) – kamahl 2010-06-13 20:15:57