Multiple conditions with CASE statements
Posted
by Pavan Reddy
on Stack Overflow
See other posts from Stack Overflow
or by Pavan Reddy
Published on 2010-06-13T07:53:31Z
Indexed on
2010/06/13
8:32 UTC
Read the original article
Hit count: 213
I need to query some data. here is the query that i have constructed but which isn't workig fine for me. For this example I am using AdventureWorks database.
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
This is not working for me. How can I have multiple where condition clauses in the THEN
of the the same CASE
? How can I make this work?
© Stack Overflow or respective owner