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 |
|
shyaagi
Starting Member
1 Post |
Posted - 2010-11-22 : 12:58:55
|
| Hi my data isId amount213 500214 600215 700215 400215 550216 300216 600217 500I am looking for output like belowId amount213 500214 60021501 70021502 40021503 55021601 30021602 600217 500if same id repetes then it has to add 01,02,03 after the idis it possible |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-11-22 : 13:08:18
|
| with cte as(select id, amount, seq = row_number() over (partition by id order by amount) from tbl)select id, seq, amount from cteor maybewith cte as(select id, amount, seq = row_number() over (partition by id order by amount) from tbl)select c1.id + case when c2.seq <> 1 then right('00' + convert(varchar(2),c1.seq),2) else '' end, amountfrom cte c1join (select id, seq = max(seq) from cte group by id) c2on c1.id = c2.idHopefully Mr. Celko is still around to give a pertinent comment about this.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|