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

t-sql case statement in a select

$
0
0

When I execute the following t-sql 2012 statement, the "NO Prod' value is not
being displayed from the sql listed below:
 
 
SELECT DISTINCT
IsNull(cs.TYPE,'') as type,
CASE IsNull(Course.TYPE,'')
WHEN 'AP' then 'AP Prod'
WHEN 'IB' then 'IB Prod'
WHEN 'HR' then 'HR Prod'
WHEN '' then 'NO Prod'
END AS label
FROM CustSection cs
INNER JOIN dbo.Person p on P.personID = cs.personID
Left join customCustomer cs564 on cs564.personID = p.personID and
cs564.attributeID ='564'
   where ( cs.type is null and cs564.attributeID = null)    
     or
    (cs.type IN ('HR','AP') OR
      (cs.type='IB' AND SUBSTRING(cs.code,1,1)='3'))  
ORDER BY label
 
What I want is for 'NO Prod' to be displayed when
cs.type is null and cs564.attributeId  is null.

Thus can you tell me how to fix query above so the 'NO Prod'  value is displayed in the
select statement listed above?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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