Skip to Content
Former Member
Dec 09, 2014 at 02:27 PM

OR/LIKE issue in command line


The OR portion of my command line below in red causing my sql statement to ignore the date range and MRN in my where clause. Any suggestions on how to fix this?

select distinct
penc.pat_enc_csn_id, penc.pat_id, penc.contact_date, epi.episode_id, edg9.code, as epi_type, as epi_status, vf.mrn,
vf.pat_name, payor.payor_name, rfsrc.referring_prov_nam, floor((penc.contact_date - pat.birth_date)/365.25) as Age, as episode_name, epi.start_date as epi_start, epi.end_date as epi_end

from episode epi
left outer join episode_link elink on epi.episode_id = elink.episode_id
left outer join pat_enc penc on elink.pat_enc_csn_id = penc.pat_enc_csn_id
left outer join pat_enc_dx pdx on penc.pat_id = pdx.pat_id
left outer join edg_current_icd9 edg9 on pdx.dx_id = edg9.dx_id
-- left outer join pat_enc_dx pdx on penc.pat_enc_csn_id = pdx.pat_enc_csn_id -- the LBP codes retrieved in the temp table above are used to isolate the patient encounter visits
--left outer join clarity_edg edg on pdx.DX_ID = edg.DX_ID
left outer join clarity_dep dep on penc.department_id = dep.department_id
left outer join clarity_epm payor on penc.visit_epm_id = payor.payor_id
left outer join epicadm.v_fv_mrn vf on penc.pat_id = vf.pat_id
left outer join patient pat on penc.pat_id = pat.pat_id
left outer join referral_source rfsrc on penc.referral_source_id = rfsrc.referring_prov_id
left outer join ZC_SUM_BLK_TYPE zep_type on epi.SUM_BLK_TYPE_ID = zep_type.SUM_BLK_TYPE_ID
left outer join ZC_EPI_STATUS zep_status on epi.status_c = zep_status.epi_status_c

where (penc.contact_date Between To_Date ('06/01/2014', 'mm/dd/yyyy')
And To_Date ('09/30/2014', 'mm/dd/yyyy'))
and penc.department_id in (450024,460023,54513,55113,55411,55706,54313,54407)
and penc.appt_prc_id in ('868','870','871','872','1761')
and penc.enc_type_c = '3'
and penc.appt_status_c = 2
and dep.RPT_GRP_FOURTEEN_C = 21
and edg9.code in ('720.1','721.3', '721.39','721.42','721.9','721.90','722.6','722.69','722.93','724.39',
'739.49','846.39','846.8','846.99','847.2','847.29','738.4', '724.3',
or (edg9.code like '722.10%' or edg9.code like '722.52%'
or edg9.code like '724.02%' or edg9.code like '724.2%' or
edg9.code like '846.0%' or edg9.code like '847.2%' or edg9.code like '724.4%'
or edg9.code like '724.6%')
and vf.mrn in ('0000094377','0004047782')