Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Query; most recent status for each date

Posted on 2011-09-26
2
Medium Priority
?
330 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 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

604 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