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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Ranking Transactions

Author  Topic 

Netgame
Starting Member

4 Posts

Posted - 2009-08-31 : 16:19:50
Hello,

I have a header table with a customer number and a detail table with multiple transactions for the header. I am wanting to find a way to gather these detail transactions but rank them 1 through whatever.

Can someone help me figure this one out? I wsa thinking of Rank but I could not get that one to work.

My example would be...

CustNum DetailTransaction
1234 1
1234 2
1234 3
1234 4
3456 1
3456 2
3456 3
3456 4
7891 1
7891 2
8555 1

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-31 : 16:28:04
select h.*,d.*,row_number() over (partition by h.custnum order by h.custnum) as rnk
from header h
join detail d on h.custnum = d.custnum


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Netgame
Starting Member

4 Posts

Posted - 2009-08-31 : 16:38:49
Awesome.. Thank you. That works just fine.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-31 : 16:43:59
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -