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
 Condition
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cottage125
Starting Member

32 Posts

Posted - 10/04/2012 :  18:33:06  Show Profile  Reply with Quote

I have a table with 2 columns. plan_type and signles (Y and N -- only 2 values).

If plan_type = static AND All signles are Y then Print 'A'

If plan_type = static AND All signles are either Y OR N then Print 'B'

If plan_type = static AND All signles are N then Print 'C'

I know it sounds simple but I am not sure the code for this.

If Plan_type = static AND select * from table where-- how to check if all signles in this table are Y only?? Whats the condition?

Please help. Thanks

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 10/04/2012 :  18:53:19  Show Profile  Reply with Quote
I'm not sure I understand the logic. I made a guess, but if that isn't what you want, please post DDL, DML (Sample date) and expected output.

DECLARE @Foo TABLE (plan_type varchar(100), signles CHAR(1))
INSERT @Foo VALUES
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y'),
('static', 'Y')

SELECT
    CASE 
        WHEN COUNT(*) = COUNT(CASE WHEN signles = 'Y' THEN 1 ELSE NULL END) THEN 'A' 
        WHEN COUNT(*) = COUNT(CASE WHEN signles = 'N' THEN 1 ELSE NULL END) THEN 'C' 
        ELSE 'B'
    END AS ColumnName
FROM 
    @Foo
WHERE 
    plan_type = 'static'
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.08 seconds. Powered By: Snitz Forums 2000