Experts Exchange connects you with the people and services you need so you can get back to work.
Your question, your audience. Choose who sees your identity—and your question—with question security.
WITH temp2 as
,row_number() over (partition by county_cd order by bias) AS RN
,investigation_accepted_dt as investigation_start_dt,action_dt as inv_completion_dt
,cast(rand() * 10000 as integer) as BIAS
picklist_value_cd as county_cd,value_tx
AND DELETE_SW ='N'
AND picklist_value_cd NOT IN('3824','3825','3826')
t1.referral_id,worker_id,investigation_accepted_dt,action_dt,sf.primary_county_cd as county_cd
,ssf.first_nm AS supervisor_first_nm,ssf.last_nm AS supervisor_last_nm
,sf.first_nm AS worker_first_nm, sf.last_nm AS worker_last_nm
,tbl_chs.client_id as ch_client_id, tbl_chs.last_nm as ch_last_nm
,tbl_chs.first_nm as ch_first_nm, tbl_chs.middle_nm as ch_middle_nm
,tbl_chs.dob_dt as ch_dob_dt
,CHESSIE.F_PRIM_WORKER_ID(referral_id ,'2957') as worker_id
from tb_referral rf
left join tb_supervisor_approvals sa
on (sa.approval_key_id = rf.referral_id
and (sa.delete_sw = 'N' or sa.delete_sw ='N')
and sa.approval_status_cd ='3047'
and sa.approval_nature_cd ='2967'
and sa.entity_type_cd ='2957')
WHERE (rf.delete_sw='N' or rf.expungement_sw='Y')
and investigation_accepted_dt between DATE('08/20/2010') and DATE('10/20/2010')
inner join tb_staff sf
on (sf.staff_id = t1.worker_id AND sf.delete_sw ='N')
inner join tb_county_unit cu
on (sf.primary_county_unit_id = cu.county_unit_id AND cu.delete_sw ='N' )
inner join tb_staff ssf
on (ssf.staff_id = cu.unit_supervisor_id AND ssf.delete_sw ='N' )
select cl.client_id ,cl.dob_dt, referral_id ,first_nm ,last_nm,middle_nm
from tb_referral_clients rc
inner join tb_client cl
on ( cl.client_id = rc.client_id and cl.delete_sw ='N' and rc.delete_sw ='N')
where rc.delete_sw ='N'
and referral_client_id in (select referral_client_id from tb_client_roles
where delete_sw = 'N'
and role_cd ='2085'
and referral_client_id in (select referral_client_id
where delete_sw ='N'
on ( tbl_chs.referral_id = t1.referral_id )
on t2.county_cd = pl_vals.county_cd
order by pl_vals.county_cd
) AS T
ORDER BY 15
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.