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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Return value from select
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

169 Posts

Posted - 04/09/2013 :  09:22:52  Show Profile  Reply with Quote
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

Posting Yak Master

153 Posts

Posted - 04/09/2013 :  09:58:33  Show Profile  Reply with Quote

select id, max(case when col1 in ('91','99') then 'Yes' else 'No' end) as flag
from yourtable
group by id
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.36 seconds. Powered By: Snitz Forums 2000