Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max Date

Status
Not open for further replies.

LAM986

Programmer
Nov 4, 2009
15
US
Hello,
My data looks like:

StudentID Review1 Review2
228017 12/30/2008 NULL
228017 3/12/2009 NULL

I want it to look like:
StudentID Review1 Review2
228017 12/30/2008 3/12/2009

I'm using a simple
SELECT StudentID
, max(Review1)
, max(Review2)
FROM WBLP

Thank you
 
select S.StudentID, Min(Review1) as Review1, Max(Review1) as Review2 from WBLP

would this work?
 
I tried that and I get

StudentID Review1 Review2
228017 12/30/2008 NULL

Thanks for responding

 
nope, you didn't tried it right :)
Code:
select S.StudentID, 
       Min(Review1) as Review1, 
       Max([COLOR=red][b]Review1[/b][/color]) as Review2
FROM WBLP


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Based on the data you posted you should have gotten the correct result (not NULL) using the query I provided.
 
:))) Did it work because the last portion was in red? :)))))
 
Actually, there was a typo in the query - there should not be S.StudentID - should be just StudentID (also I think I meant to add GROUP BY StudentID)
 
Makros, I'm sorry. Yours would have worked, I didn't see Review1 on the second field. I apologize.
 
No problem, there were several typos in the query anyway.
 
One more question. How do I handle if Review1 is NULL

So the data looks like:

StudentID Review1 Review2
228017 12/30/2008 NULL
228017 NULL NULL

The result I get in this case is below, when I would now want to put NULL in review2

StudentID Review1 Review2
228017 12/30/2008 12/30/2008
 
Try

Code:
select S.StudentID,        Min(Review1) as Review1,        case when min(Review1) = Max(Review1) then NULL else Max(Review1) end as Review2 FROM WBLP
 
Thanks again guys. I knew I had to do a Case statement, but couldn't get the right outcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top