SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Last rep billing a client
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jaimealvarez
Starting Member

29 Posts

Posted - 12/27/2012 :  09:41:22  Show Profile  Reply with Quote
Hi,
I need a report that shows the last day that a client was billed and also the rep name that billed the client.

I know how to do the last billed date using MAX, but not sure how to bring the name too.

My fields are:

Client, date, Rep
Table T

So basically I need only one line per client, showing the last date and the Rep name.

ANy help would be appreciated.
Thanks!

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/27/2012 :  09:45:38  Show Profile  Reply with Quote
If you have just one client for whom you want to get the data
SELECT TOP (1) Client, Date, Rep 
FROM Tbl t
WHERE Client = 'JaneDoe'
ORDER BY Date DESC
For all clients

SELECT Client, Date, Rep
FROM
(
	SELECT *,
	ROW_NUMBER() OVER (PARTITION BY Client ORDER BY Date DESC) AS RN
	FROM Tbl
)s
WHERE RN = 1;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000