Solved

SQL Query; most recent status for each date

Posted on 2011-09-26
2
267 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
Comment Utility
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
Comment Utility
Ouch! I thought this was going to be hard...
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now