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.
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 #testINSERT INTO #testSELECT '001','Y'UNION ALLSELECT '001','Y'UNION ALLSELECT '002','N'UNION ALLSELECT '002','N'UNION ALLSELECT '004','N'UNION ALLSELECT '004','N'UNION ALLSELECT '004','Y'/*Rule: If there is atleast one Y for Indication then 'Active' otherwise 'Inactive'OutPut:001 Active002 Inactive004 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 StatusFROM #testGROUP BY Id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
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 |
|
|
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 StatusFROM #test[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-03-08 : 01:45:24
|
Thank u--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-08 : 05:28:06
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|