Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
baylor2016
Creator
Creator

Best way to write load script which uses the same CTE multiple times!!!

Hi,

I am using the same CTE statement (query to get patients) for multiple times in my load script in order to get different information like lab test, visit info, medication. I think there might be a way to avoid this duplication. I heard about QVD, not sure whether it is a good choice.

Thanks

Longmatch

My code like this:

Patient:

SQL

WITH Patients as (

SELECT patient_id, patient_name, patient_age

FROM patient

WHERE age >18

)

select *

from Patient;

Medication:

SQL

WITH Patients as (

SELECT patient_id, patient_name, patient_age

FROM patient

WHERE age >18

)

select patient_id, medication

from medication a

inner join patients b on a.patient_id = b.patient_id;

Lab:

SQL

WITH Patients as (

SELECT patient_id, patient_name, patient_age

FROM patient

WHERE age >18

)

select patient_id, labTest

from labTest a

inner join patients b on a.patient_id = b.patient_id;

2 Replies
jagan
Partner - Champion III
Partner - Champion III

HI,

Try like this

Patient:

SELECT patient_id, patient_name, patient_age

FROM patient

WHERE age >18;

Medication:

LEFT KEEP(Patient)

select patient_id, medication

from medication;

Lab:

LEFT KEEP(Patient)

select patient_id, labTest

from labTest;

Hope this helps you.

Regards,

Jagan.

marcus_sommer

You could use Variables to store redundant script- or expression(parts) and in your example might be a for each loop for your sql-loadings possible - but if there are only those few loads and script-lines I wouldn't change it - readability of script is often a more important point then it's short.

- Marcus