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 |
|
PurpleSun
Yak Posting Veteran
50 Posts |
Posted - 2007-02-23 : 09:30:53
|
| I'm stuck with the problem that looks very simple, but ...I have a table:ID LineNumber CaseNumber1------ 01------ 2862------ 01------ 2873------ 02------ 2884------ 81------ 2875------ 83------ 2886------ 85------ 2887------ 83------ 290If this table has miltiple records with the same CaseNumberI have to update LineNumber in these records with the smallest value,so my result should look like:ID LineNumber CaseNumber1------ 01------ 2862------ 01------ 2873------ 02------ 2884------ 01------ 287 updated5------ 02------ 288 updated 6------ 02------ 288 updated7------ 83------ 290Please help. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-23 : 09:35:41
|
Try this:Update t1Set LineNumber = t2.LineNumberFrom tbl t1JOIN (select CaseNumber, Min(LineNumber) as LineNumber From tblGroup by CaseNumber) as t2on t1.CaseNumber = t2.CaseNumber Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
PurpleSun
Yak Posting Veteran
50 Posts |
Posted - 2007-02-23 : 09:43:46
|
| It does the job.Thanks a lot |
 |
|
|
|
|
|