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)
 Finding Last Entry

Author  Topic 

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2009-05-26 : 07:30:04
Morning All,

May I seek my help here..

I have a table keeping history of loan defaulters, the table holds all entries of any loan issues. I want to get the last entry of each accounts/transactions.

Sample data

TransID Period Days
AREPDLD0724300270 20080401 406
AREPDLD0725500322 20080512 365
AREPDLD0725500322 20080612 334
AREPDLD0725500322 20080412 395
AREPDLD0725500322 20080712 304
AREPDLD0725500322 20080312 426
AREPDMG0722610484 20071016 574
AREPDMG0722611567 20070815 636
AREPDMG0722614023 20070822 629
AREPDMG0722614023 20071022 568
AREPDMG0722614023 20070922 598
AREPDMG0722614075 20070920 600
AREPDMG0722814902 20080124 474
AREPDMG0722814902 20071024 566
AREPDMG0722814902 20071224 505
AREPDMG0722814902 20080724 292
AREPDMG0722814902 20080324 414
AREPDMG0722814902 20070824 627
AREPDMG0722814902 20071124 535
AREPDMG0722814902 20080624 322

for example, here AREPDLD0725500322 I want to return 200807 with 304.

Thanks.

I sign for fame not for shame but all the same, I sign my name.

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2009-05-26 : 07:47:43
Thanks All solved...

I used row_number(), and got it solved...

ROW_NUMBER() OVER(PARTITION BY x.transid ORDER BY x.period desc) NumEntry

Dont mind me, I want to deliver in time.. this didnt gimme chance to try mind best first..

I sign for fame not for shame but all the same, I sign my name.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-26 : 13:01:25
also see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx
Go to Top of Page

ergen
Starting Member

5 Posts

Posted - 2009-05-26 : 15:50:00
example of sollution you can find here : http://www.jacek-szarapa.com/index.php?p=sql&d=32

----------------
Jacek Szarapa
http://www.jacek-szarapa.com
Go to Top of Page
   

- Advertisement -