I'm looking for the right syntax or even if I'm doing this right. I want to find records with certain SIM numbers and when I find that group I only want the ones that also have other certain SIM numbers.
What I have below errors out "near the keyword IF". Am I supposed to be doing a join instead or am I getting close with what I have?
SELECT c.source_id, pe.enc_nbr, c.SIM
FROM
patient_encounter pe
left outer join Charges c on (pe.person_id = c.person_id and pe.enc_id = c.source_id)
Where c.SIM in ( '99211', '99212', '99213', '99214', '99215', '99241',)
(
If exists (select SIM from charges where SIM in ('G8443', 'G8445', 'G8446')
)
Thank you.
What I have below errors out "near the keyword IF". Am I supposed to be doing a join instead or am I getting close with what I have?
SELECT c.source_id, pe.enc_nbr, c.SIM
FROM
patient_encounter pe
left outer join Charges c on (pe.person_id = c.person_id and pe.enc_id = c.source_id)
Where c.SIM in ( '99211', '99212', '99213', '99214', '99215', '99241',)
(
If exists (select SIM from charges where SIM in ('G8443', 'G8445', 'G8446')
)
Thank you.