I am trying to find out and flag if patient had an x-ray within one day when they first showed up in ER.
SELECT perosonID,
xray_code,
xray_date,
admit_date,
CASE
WHEN xray_code IN ( '212', '345', '489' )
AND admit_date BETWEEN DateAdd(day, 0, xray_date)
AND DateAdd(day, 1, xray_date) THEN 1
ELSE 0
END AS flag
FROM my table
my results seem to be wrong and I am not sure what I am doing wrong here. thanks
Select perosonID
, xray_code
, xray_date
, admit_date
, Case when xray_code in (‘212’, 345’, ‘489’)
and DATEDIFF(DAY, admit_date, xray_date) <= 1
then 1
else 0 end as flag
from my table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.