Solved

SQL Query; most recent status for each date

Posted on 2011-09-26
2
301 Views
Last Modified: 2012-08-14
I don't know where to start with this.

I need a query to return the most recent status for a given client. Using SQL Server2008. There are multiple dates and multiple statuses.

The status field can include any number of statuses.  I don't know what will be in that field. The query should generate a list of the existing statuses for the given client and then get the most recent date for each status.

@ClientNum = '6000'

ClientNum      Date      Status
6000      06/14/10           Started
6000      06/24/10           Process1
6000      07/04/10           Process2
6000      07/14/10           Finished

Can you help me??
0
Comment
Question by:TadSter
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36600972
SELECT ClientNum, MAX([Date]) AS LastDate, Status
FROM SomeTable
WHERE ClientNum = '6000'
GROUP BY ClientNum, Status

Open in new window

0
 
LVL 2

Author Closing Comment

by:TadSter
ID: 36601365
Ouch! I thought this was going to be hard...
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question