SELECT [pat_id] ,[msr_Date] FROM [BPSD].[dbo].[Measurements] order by pat_id, msr_date
SELECT pat_id, count(case mgp_id when 2 then 1 else null end) as [A 11 + A 12], count(case mgp_id when 23 then 1 else null end) as [N 02 Analgetika], FROM [BPSD].[dbo].[vw_PatientMedicines] where ((pmd_StartDate <= msr_Date) or (pmd_StartDateUnknown = 1)) and pmd_EndDate <= msr_Date group by pat_id order by pat_id
From novice to tech pro — start learning today.