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 |
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2009-01-21 : 01:07:23
|
| Table :sales_hdr sid stotal---- -----------s001 15000s002 12000Table :Sales_dtlsid itm_id qty---- ------ -----------s001 i001 2s001 i002 10s001 i003 100s002 i022 1s002 i033 125Just the output should include snobased on sales id(sid)Tried:select row_number() over (order by hdr.sid,itm_id,qty) as s_no,hdr.sid,itm_id,qty from sales_hdr hdr inner join sales_dtl dtlon hdr.sid = dtl.sids_no sid itm_id qty-------------------- ---- ------ -----------1 s001 i001 22 s001 i002 103 s001 i003 1004 s002 i022 15 s002 i033 125Actual output should be :s_no sid itm_id qty-------------------- ---- ------ -----------1 s001 i001 22 s001 i002 103 s001 i003 1001 s002 i022 12 s002 i033 125can any one help me? |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-21 : 01:09:38
|
| use rank() or dense_rank() functions |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-21 : 01:10:33
|
| select row_number() over (partition by hdr.sid order by hdr.sid,itm_id,qty) as s_no,hdr.sid,itm_id,qtyfrom sales_hdr hdr inner join sales_dtl dtlon hdr.sid = dtl.sidJai Krishna |
 |
|
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2009-01-21 : 01:12:39
|
Thanks Jai krishna.its working fine.Txs a lot..quote: Originally posted by Jai Krishna select row_number() over (partition by sid order by hdr.sid,itm_id,qty) as s_no,hdr.sid,itm_id,qtyfrom sales_hdr hdr inner join sales_dtl dtlon hdr.sid = dtl.sidJai Krishna
|
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-21 : 01:14:47
|
| WelcomeJai Krishna |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-21 : 08:43:42
|
quote: Originally posted by bklr use rank() or dense_rank() functions
how would it give you unique numbers for each sid group? |
 |
|
|
|
|
|
|
|