Below is the query I'm working with - I need to get the MAX date for each of the PhaseEndDt. I've tried the
(SELECT Max(v) FROM (VALUES (aphase1.updated_ts), (aphase2.updated_ts), (aphase3.updated_ts)) AS VALUE(v)) AS [MaxDate]
but it isn't working :-( any help would be greatly appreciated!
SELECT
dc.case_id,
aphase1.identifier_value AS "phase1",
aphase1.updated_ts AS "phase1_enddt",
aphase2.identifier_value AS "phase2",
aphase2.updated_ts AS "phase2_enddt",
aphase3.identifier_value AS "phase3",
APHASE3.UPDATED_TS AS "Phase3_EndDt"
FROM cmreporting.d_solution ds
INNER JOIN cmreporting.d_case dc ON ds.solution_sqn = dc.solution_sqn
LEFT JOIN cmreporting.a_identifiers aphase1 ON aphase1.identifier_value = 'Phase 1' AND dc.case_ID = aphase1.group_ID
LEFT JOIN cmreporting.a_identifiers aphase2 ON aphase2.identifier_value = 'Phase 2' AND dc.case_ID = aphase2.group_ID
LEFT JOIN cmreporting.a_identifiers aphase3 ON aphase3.identifier_value = 'Phase 3' AND dc.case_ID = aphase3.group_ID