i need to use this query to return records with the most recent NoteDate, instead of returning duplicate records showing each note date. i thought that putting the ‘MAX’ in front of t.notedate would get rid of the duplicate records but they still show up.
SELECT c.ContactId, MAX(t.notedate),c.Source, c.FirstName, c.LastName, c.Phone1, crCallResultCode, crTotalCallCount
FROM dbo.t_Contact c inner join t_notes t on c.contactid=t.contactid
WHERE
(c.Source IN ('Cabo10MC', 'BOWN10')) AND
(c.crCallResultCode NOT IN ('V02', 'S01', 'CNC', 'R99','U01', 'U02', 'U03')) AND
(DATEDIFF(ww, crNextCallDateTime, GETDATE()) = 0)OR (crNextCallDateTime = '1/1/1900')AND
(c.Phone1 NOT IN
(SELECT phone
FROM lema.dbo.tswlivetours
WHERE TourDate > getdate() AND TourStatus IN ('showed')))
group by c.ContactId, c.Source, c.FirstName, c.LastName, c.Phone1, crCallResultCode, crTotalCallCount,t.notedate
Remove t.notedate from your group by clause.