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 |
|
mummy
Starting Member
9 Posts |
Posted - 2009-02-27 : 03:57:24
|
| Hi All,I have a table like below:Status TicketNo----------------S XYZ444S DSL314N ABC400S ABC400N JXM542S JXM542N XMN005S SDD002S XKK003i would like to remove records(bold ones above) where the Status is "S" for same "TicketNo".Expected Results:Status TicketNo----------------S XYZ444S DSL314N ABC400N JXM542N XMN005S SDD002S XKK003Can anyone please help me to solve this problem out. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-27 : 03:59:03
|
| try thisselect min(status),ticketno from tablename group by ticketno |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-27 : 04:23:20
|
| Check this once,declare @temp table ( Status varchar(32),TicketNo varchar(32))insert into @tempselect 'S','XYZ444' union allselect 'S','DSL314' union allselect 'N','ABC400' union allselect 'S','ABC400' union allselect 'N','JXM542' union allselect 'S','JXM542' union allselect 'N','XMN005' union allselect 'S','SDD002' union allselect 'S' ,'XKK003'delete t from( select status,ticketno,row_number() over ( partition by ticketno order by ticketno) as rn from @temp) twhere t.rn > 1select * from @temp |
 |
|
|
mummy
Starting Member
9 Posts |
Posted - 2009-02-27 : 06:08:40
|
quote: Originally posted by bklr try thisselect min(status),ticketno from tablename group by ticketno
Hello sir, I have 1 more column in the table with 'ticketcount' and need to remove duplicate values based on 1)'status':- what ever counter, if 'N' & 'S' for same ticket then 'S' should be removed2)'counter':- if status and ticketno are same with status 'S' then should check the 'counter' and remove the smaller counter.bold ones should be removed.Counter Status TicketNo-----------------------10 S XYZ44411 S DSL31412 N ABC40013 S ABC40014 N JXM54215 S JXM54210 N XMN00511 S SDD00214 S XKK00315 S XKK00318 S UVW33317 S UVW333expected results like this:Counter Status TicketNo-----------------------10 S XYZ44411 S DSL31412 N ABC40014 N JXM54210 N XMN00511 S SDD00215 S XKK00318 S UVW333Please help... |
 |
|
|
|
|
|
|
|