I want to create a new column, which shows the latest appointment date for the same HC_Number.Example: HC_Number- 2552 has 3 appointments in december- 2nd december, 7th december and 25th december. So the new column showing latest appointment will show 25th december for both the records on 2nd & 7th december.
Select
a.HC_NUMBER
,a.APPOINTMENT_TYPE_FULL
,a.APPOINTMENT_DATE
,a.person_id
,a.APPT_BOOKED_BY
FROM [HIM_Clinical].[dbo].[APPOINTMENT_DATA] a (nolock) -----Main Data----
left join [ODS_CCL].[dbo].[ODS_CCL_ENCOUNTER] e (nolock) on a.ENCNTR_ID=e.ENCNTR_ID
WHERE a.APPOINTMENT_TYPE_FULL like '%Smart Checkup%'
AND a.Appointment_Status IN ('Checked Out','Checked In','No Show','Confirmed')
AND a.APPOINTMENT_DATE>='2020-12-01' AND a.APPOINTMENT_DATE<='2020-12-31'