Solved

SQL Query; most recent status for each date

Posted on 2011-09-26
2
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

728 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