Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jaimealvarez
Starting Member

31 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  
 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.09 seconds. Powered By: Snitz Forums 2000