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

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

maevr
Posting Yak Master

Sweden
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

singularity
Posting Yak Master

151 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  
 New 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.1 seconds. Powered By: Snitz Forums 2000