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
 please Help

Author  Topic 

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-08 : 00:39:13

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

52326 Posts

Posted - 2013-03-08 : 01:11:18
[code]
SELECT Id,
MIN(CASE WHEN Ind ='Y' THEN 'Active' ELSE 'Inactive' END) AS Status
FROM #test
GROUP BY Id
[/code]

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

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-08 : 01:17:32
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

52326 Posts

Posted - 2013-03-08 : 01:26:08
[code]
SELECT DISTINCT Id,
MIN(CASE WHEN Ind ='Y' THEN 'Active' ELSE 'Inactive' END) OVER (PARTITION BY Id) AS Status
FROM #test
[/code]

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

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-08 : 01:45:24
Thank u

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-08 : 05:28:06
welcome

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

Go to Top of Page
   

- Advertisement -