Solved

Select MIN date from view

Posted on 2004-03-24
2
317 Views
Last Modified: 2008-02-26
I have a view (vwHistory).  This view is a history of events that have happened to a claim.  It looks something like this:

vwHistory
ClaimNumber (varchar)
EventDate (DateTime)
Attribute1 (varchar)
Attribute2 (varchar)
Attribute3 (varchar)

ClaimNumber and EventDate together make a composite key.

I need a select statement that will give me all of the data values for the earliest EventDate for a particular claim number.

For example if my table looks like this:

ClaimNumber   EventDate     Att1        Att2      Att3
1                     1/1/04          A            B          C
1                     1/2/04          D            E          F
1                     1/3/04          G            H          I
2                     1/1/04          J             K          L
2                     1/2/04          M           N          O
3                     1/5/04          P            Q          R

Then my result set would look like this:

ClaimNumber   EventDate     Att1        Att2      Att3
1                     1/1/04          A            B          C
2                     1/1/04          J             K          L
3                     1/5/04          P            Q          R


Attributes 1 - 3 may or may not be identical for each row.


Thanks in advance,
HawkeyeNash
0
Comment
Question by:HawkeyeNash
[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 7

Accepted Solution

by:
ChrisFretwell earned 125 total points
ID: 10671741
Here's one way

select vw.claimnumber, vw.eventdate, vw.att1, vw.att2,vw.att3
from vwhistory vw join
(select claimnumber, min(eventdate) as mindate from vwhistory group by claimnumber) as v2 on vw.claimnumber = v2.claimnumber and vw.eventdate = v2.mindate
order by vw.claimnumber
0
 

Author Comment

by:HawkeyeNash
ID: 10671811
Thanks, Chris.

Had the join in the wrong place.

Much appreciated.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

632 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