Skip to Content
0
Nov 14 at 06:55 PM

Capture a Value based on Times

170 Views

I am trying to capture a number value based on when two times occurred. So I need the value that was recorded for the LAST meas.RECORDED_TIME that occurred before the Administration Time of a Medication. I am using the function 'Max' for my meas.RECORDED_TIME but I am not sure how to add in my Medication Time to pull the number I need ???

--Pain Score FLO ID = 18

LEFT OUTER JOIN

(

select distinct ifr.pat_id,ifmwdt.MEAS_VALUE as Pain_Score

from IP_FLWSHT_REC ifr

inner join (SELECT distinct rec.pat_id,max(meas.RECORDED_TIME) as Pain_Score

from ip_flwsht_rec rec

inner join [CLARITY].[dbo].[IP_FLWSHT_MEAS] meas on rec.fsd_id=meas.FSD_ID

where meas.flo_meas_id='18'

and meas.MEAS_VALUE is not null

group by rec.pat_id) mdt on ifr.pat_id=mdt.pat_id

inner join IP_FLWSHT_MEAS ifmwdt on ifr.FSD_ID=ifmwdt.FSD_ID and mdt.Pain_Score=ifmwdt.RECORDED_TIME

where ifmwdt.FLO_MEAS_ID='18' and ifmwdt.MEAS_VALUE is not null

)fmidwt on PEH.PAT_ID =fmidwt.PAT_ID

image.png

Attachments

image.png (7.3 kB)