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)
 Date selection question

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-28 : 05:33:12
I have a table:

amount paymentdate clientid
----- ----------- --------

10.00 2009-06-20 101200
12.00 2009-06-22 100333
10.00 2009-06-22 101200
17.50 2009-06-23 111345
12.00 2009-06-23 101200

how can I select the latest payment date amount for client 101200 please?

Sachin.Nand

2937 Posts

Posted - 2009-10-28 : 05:44:18
select max(paymentdate) from table where client=101200

PBUH
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-10-28 : 08:05:47
select amount,paymentdate,clientid from (select row_number() over(partiton by clientid order by paymentdate desc) as rid,* from tablename)s
where rid = 1 and clientid = 101200
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-10-28 : 10:53:54
select top 1 paymentdate, amount from MyTable where clientid = 101200 order by paymentdate desc

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -