Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 t-sql 2012 case statement in where clause

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-02-06 : 22:40:22
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?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-07 : 00:08:47
is that the complete query ? Because i don't see where you join to the table Course but you reference it at "IsNull(Course.TYPE,'')"


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-02-07 : 11:18:41
I found the answer.
Go to Top of Page
   

- Advertisement -