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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Removing Duplicates

Author  Topic 

ucal
Yak Posting Veteran

72 Posts

Posted - 2008-10-15 : 19:38:30
I have a table T1 with the following data structure

ID Flag Seq
-- -- --
1 a x
1 a y
2 a t
3 b t
3 b u
4 a m
5 c u
5 c k

I want to create a table with distinct values ID and Flag.
Any assistance will be welcomed


Expected Results

ID Flag Seq
-- -- --
1 a Multiple
2 a t
3 b Multiple
4 a m
5 c Multiple

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-15 : 20:52:49
select ID,Flag,case when count(seq)=2 then 'Multiple' else max(Seq) End as Seq
from table
group by ID,Flag
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-15 : 21:12:46
Or depending on data.

select ID,Flag,case when count(seq)>=2 then 'Multiple' else max(Seq) End as Seq
from table
group by ID,Flag
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-16 : 02:35:53
or just
select ID,Flag,case when min(seq)<>max(seq) then 'Multiple' else max(Seq) End as Seq
from table
group by ID,Flag
Go to Top of Page
   

- Advertisement -