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?