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 2008 Forums
 Transact-SQL (2008)
 Help with Case Statement

Author  Topic 

ALSZ37
Starting Member

25 Posts

Posted - 2015-02-17 : 11:27:14
Good Morning,

I have a "Listing" table that has a dispo and status column and i'm joining to a look-up table(Zstatus) for the status. I'm having trouble with the 3rd condition and not sure how to put that in the Case statement.

Conditions:
Dispo is 2 then 'Inactive'
Dispo is 1 then pull the status
Dispo is 1 and status is null then 'Listed'


select case (a.dispo)
when 2 then 'Inactive'
else b.name end as 'Status'
from listing a join Zstatus b on a.status = b.id


gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-17 : 11:28:37
select case
when a.dispo = 2 then "inactive'
when a.dispo = 1 and a.status is null then 'Listed'
when a.dispo = 1 then a.name
else b.name
end as 'Status'
from listing a join Zstatus b on a.status = b.id
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2015-02-17 : 14:57:01
[code]
select case (a.dispo)
when 2 then 'Inactive'
else isnull(s.name, 'Listed') end as 'Status'
from listing l
left outer join Zstatus s on l.status = s.id

[/code]
Go to Top of Page

ALSZ37
Starting Member

25 Posts

Posted - 2015-02-17 : 18:05:27
quote:
Originally posted by gbritton

select case
when a.dispo = 2 then "inactive'
when a.dispo = 1 and a.status is null then 'Listed'
when a.dispo = 1 then a.name
else b.name
end as 'Status'
from listing a join Zstatus b on a.status = b.id



Thank you!
Go to Top of Page

ALSZ37
Starting Member

25 Posts

Posted - 2015-02-17 : 18:05:48
quote:
Originally posted by ScottPletcher


select case (a.dispo)
when 2 then 'Inactive'
else isnull(s.name, 'Listed') end as 'Status'
from listing l
left outer join Zstatus s on l.status = s.id





Thank you!
Go to Top of Page
   

- Advertisement -