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

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 03/08/2013 :  00:39:13  Show Profile  Reply with Quote

CREATE TABLE #test(Id VARCHAR(5), Ind CHAR(1))
--Lets insert some data in this table:
--DROP TABLE DELETE #test
INSERT INTO #test
SELECT '001','Y'UNION ALL
SELECT '001','Y'UNION ALL
SELECT '002','N'UNION ALL
SELECT '002','N'UNION ALL
SELECT '004','N'UNION ALL
SELECT '004','N'UNION ALL
SELECT '004','Y'
/*
Rule: If there is atleast one Y for Indication then 'Active' otherwise 'Inactive'
OutPut:
001 Active
002 Inactive
004 Active */


--
Chandu

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/08/2013 :  01:11:18  Show Profile  Reply with Quote

SELECT Id,
MIN(CASE WHEN Ind ='Y' THEN 'Active' ELSE 'Inactive' END) AS Status
FROM #test
GROUP BY Id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 03/08/2013 :  01:17:32  Show Profile  Reply with Quote
Thank you visakh.. i want solution without using GROUP BY clause.. In my original query i can't use GROUP BY clause because i have CSV forms for several columns with different tables

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/08/2013 :  01:26:08  Show Profile  Reply with Quote

SELECT DISTINCT Id,
MIN(CASE WHEN Ind ='Y' THEN 'Active' ELSE 'Inactive' END) OVER (PARTITION BY Id) AS Status
FROM #test


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 03/08/2013 :  01:45:24  Show Profile  Reply with Quote
Thank u

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/08/2013 :  05:28:06  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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