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
 General SQL Server Forums
 New to SQL Server Programming
 Return value from select

Author  Topic 

maevr
Posting Yak Master

169 Posts

Posted - 2013-04-09 : 09:22:52
I have a table that i need to iterate through and return Yes or No
if a column contains the value 91 or 99.

The column has multiple rows with the same id but if the column col1 contains 91 or 99 then it should return 'Yes' otherwise No. Only one value should be returned.

Example table:

id col1
1 00
1 96
2 91
3 00
3 99

Expected output:
1 No
2 Yes
3 Yes

singularity
Posting Yak Master

153 Posts

Posted - 2013-04-09 : 09:58:33
[code]
select id, max(case when col1 in ('91','99') then 'Yes' else 'No' end) as flag
from yourtable
group by id
[/code]
Go to Top of Page
   

- Advertisement -