If an image is marked as active and a person clicks on the link they should be taken to the active image otherwise they should be taken to the (MAX) most recent image uploaded. My first select works but not entirely.
Here’s my select:
select
b.image_id, b.active, c.id as event_id
from event.dbo.lite() a
left outer join event.dbo.dia_tracker b on a.code = b.patient_id
and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = {$patient->hex})
left outer join event.dbo.ev c on a.code = c.patient_id and c.task_id in ('WR','RC') and c.status<>0
where a.code = {$patient->hex}
Here’s my new select that I need a bit of help with.
select
image_id,
active,
case when active <>1 than image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
from event.dbo.dia_tracker
where active = '1' and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
it’s a bit of a mess atm. I was thinking I could use isnull to accomplish more in less lines of code.
update:
select
*,
ISNULL(active,image_id) as image
from event.dbo.dia_tracker
where active = '1' and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
Still need help.
It would be much easier if you would post all relevant DDL and sample data, but you can try something like this to get your
image_idAnd if it (
image_id) uniquely identifies the row you’re looking for you can try