Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

How to return multiple rows in case when condition?

$
0
0

I want to display the list of product names owned by a company.If no products found it should return a string like "NO PRODUCTS FOUND'

The query I wrote working well but when the condition does not satisfy Its not returning  "NO PRODUCTS FOUND''. Can someone help me how can I do this?

declare @Country varchar(100)='Netherlands'

SELECT     CASE WHEN count(table4.ProductName) >0 THEN table4.ProductName 
               ELSE 'NO PRODUCTS FOUND' END AS Product_list
FROM              table2 INNER JOIN
                      table1 ON table2.AccountID = table1.AccountID INNER JOIN
                      table3 ON table1.[company_ID] = table3.[company_ID] INNER JOIN
                      table4 ON table4.ProductID = table2.ProductID
WHERE    
                     table1.[country] IN (@Country)) AND table4.ProductID IN (24410, 24413, 24418, 24383,                           24384))
GROUP BY table4.ProductName 





Viewing all articles
Browse latest Browse all 12890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>