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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic

Status
Not open for further replies.

meme

Programmer
Sep 29, 2000
6
I have the following query where I am selecting the max date.I neeed to modify query where I can select the max date, but if date='1998-01-01' select the record with date='1998-01-01'.
SELECT t1a.*
FROM Table1 t1a
INNER JOIN Table2 t2a ON t1a.num = t2a.num AND t1a.id = t2a.id
INNER JOIN
(SELECT t1b.NNumber, t1b.Pin, t1b.TNumber, t1b.SNumber,
Max(convert(datetime,(t2b.edc+t2b.edy+'-'+t2b.edm+'-'+t2b.edd))) AS [date]
FROM Table1 t1b
INNER JOIN Table2 t2b ON t1b.num = t2b.num AND t1b.id = t2b.id
GROUP BY t1b.NNumber, t1b.Pin, t1b.TNumber, t1b.SNumber
HAVING COUNT(*) > 1) AS tmaxdate
ON t1a.NNumber = tmaxdate.NNumber AND t1a.Pin = tmaxdate.Pin AND
t1a.TNumber = tmaxdate.TNumber AND t1a.SNumber = tmaxdate.SNumber AND
convert(datetime,(t2a.edc+t2a.edy+'-'+t2a.edm+'-'+t2a.edd))= tmaxdate.[date]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top