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)
 Initial transaction

Author  Topic 

KG07
Starting Member

8 Posts

Posted - 2010-04-29 : 11:32:27
I am working with a database of clients, for which we have an account table and a transaction table linked by Account number. I need to query to produce every account number with it's associated initial transaction. Is there a command prompt which can be used to limit the result to just the original transaction based on earliest transaction date? Thanks!

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-04-29 : 11:36:15
Assumimg you use SQL Server 2005
select a.col1,b.col1,b.col2 from
AccountTable a inner join
(
select row_number () over(partition by AccountNumber order by TransactionDate) as rn, * from TransactionTable
) b
on a.AccountNumber = b.AccountNumber and b.rn = 1
Go to Top of Page

KG07
Starting Member

8 Posts

Posted - 2010-04-29 : 11:54:11
Well I don't understand exactly what I told it to do, but it worked. Thanks!!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-04-29 : 14:24:55
You're welcome.
Go to Top of Page
   

- Advertisement -