Case statement with multiple conditions in SQL Server

Last Reply 3 months ago By chetan

Posted 3 months ago

Is it possible to combine this two into one?

 cmp.category=case when cmp.category='' OR cmp.category IS NULL OR cmp.category IS NOT NULL then dupl.category else cmp.category end,
 cmp.category=case when cmp.status!=1 and cmp.status!=2 then dupl.category else cmp.category end,

 

Posted 3 months ago

Hi chetan,

Refer below query according to query change your query.

SQL

SELECT CustomerId , CASE WHEN CustomerId = 1 OR CustomerId = 2 AND CustomerId = 3  THEN  'True'
WHEN CustomerId = 4 THEN 'False'
ELSE 'Nothing' 
END Result
FROM Customers

 


Posted 3 months ago

i got the solution SIr from ur reference:

 

 cmp.category=case when cmp.status!=2 and (cmp.category='' OR cmp.category IS NULL OR cmp.category IS NOT NULL) then dupl.category else cmp.category end

This worked for me.