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 |
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2012-02-03 : 14:31:46
|
| Hi All, I have two tables, one is header table and one is details table. I have the following data in my Details tableDetails TableHNum DateTimeGroup SN SevereAB222 201108250554 1 3CD555 201108250554 243 2BQ77 201108210365 999 4AB222 201108250554 1 9AB222 201108250554 1 10AB222 201108250553 1 10header TableHNum DateTimeGroup SN SevereAB222 201108250554 1 3CD555 201108250554 243 2BQ77 201108210365 999 4The primary keys in HeaderTable and details table is the combination of HNum, DateTimeGroup and SN. I need to find out the higheset severe for the combination of the primary keys in the details table and then update the header table severe with that number so from the above table, I need to get this line from the details table because it has the higheset severe AB222 201108250554 1 10out ofAB222 201108250554 1 3AB222 201108250554 1 9AB222 201108250554 1 10I discareded this line because its dateTimeGroup is deifferent than other 3, I am only taking the primary keysAB222 201108250553 1 10and then update the header table this record severe to 10AB222 201108250554 1 3so this will beAB222 201108250554 1 10any help will be apprecaited. |
|
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2012-02-03 : 15:43:20
|
| I really need help with this query. any hint will also be appreciated. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-03 : 15:53:59
|
| [code]UPDATE hSET h.Severe = d.Severe FROM Header hINNER JOIN (SELECT HNum, DateTimeGroup, SN,MAX(Severe) AS Severe FROM Details GROUP BY HNum, DateTimeGroup, SN )dON d.HNum = h.HNum DateTimeGroupAND d.DateTimeGroup = h.DateTimeGroup AND d.SN = h.SN [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|