0

Can anyone help to convert the below qlikview code to snowflake SQL?

I just started with qlikview to snowflake migration and have very minimal knowledge on qlikview so need help on how applymap works here:

Left Join(EXCEL_REQ_PO_MSTR)
LOAD PO_STATUS_KEY,IF(POD_SCHED='1',ApplyMap('EXCEL_PO_STATUS_SCHEDULED',PO_STATUS_KEY,null()),
ApplyMap('EXCEL_PO_STATUS_UNSCHEDULED',POD_NBR,null()))
AS PO_STAT_DESC
RESIDENT EXCEL_REQ_PO_MSTR;
EXCEL_PO_STATUS_SCHEDULED:
MAPPING
LOAD PO_STATUS_KEY,PO_STAT;
SQL SELECT DISTINCT CONCAT_WS('|',POD_NBR,POD_LINE,POD_PART,POD_LOC,POD_PO_SITE,POD_DUE_DATE) as PO_STATUS_KEY,
/*SELECT DISTINCT CONCAT_WS('|',POD_NBR,POD_LINE,POD_PART,POD_LOC,POD_SITE,POD_DUE_DATE) as PO_STATUS_KEY,*/
CASE
WHEN "POD_END_EFF##1" IS NULL
THEN 'open'
ELSE 'closed'
END AS PO_STAT
FROM PROD_RAW.EXCEL_QADDB.VW_POD_DET
WHERE LENGTH(TRIM(POD_NBR))>0 /*AND
 SUBSTR(TRIM(POD_NBR),1,1) IN ('P')*/ AND SUBSTR(TRIM(POD_NBR),2,1) IN ('0','1','2','3','4','5','6','7','8','9') 
 AND LENGTH(TRIM(POD_PART))>0;
EXCEL_PO_STATUS_UNSCHEDULED:
MAPPING
LOAD PO_STATUS_KEY,PO_STAT;
SQL SELECT DISTINCT PO_NBR AS PO_STATUS_KEY,CASE
WHEN PO_STAT IS NULL
THEN 'open'
ELSE 'closed'
END AS PO_STAT
FROM PROD_RAW.EXCEL_QADDB.VW_PO_MSTR;

I tried below conversion:

SELECT
 CASE
 WHEN POD_SCHED = '1' THEN
 (SELECT PO_STATUS_KEY FROM dev_marts.purchasing.EXCEL_PO_STATUS_SCHEDULED)
 ELSE
 (SELECT pod_nbr FROM dev_marts.purchasing.EXCEL_PO_STATUS_UNSCHEDULED)
 END AS PO_STAT_DESC 
from dev_marts.purchasing.EXCEL_REQ_PO_MSTR;
 
marc_s
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Mar 28, 2024 at 5:11

1 Answer 1

0

Here is an example using some made up fields that are much simpler than the example you gave but you will be able to apply the concept.

Qlik Script:

DESC_MAP:
MAPPING
LOAD
ItemNum as ItemCode,
ItemName as Desc
FROM [lib://QVData/UserDescriptions.qvd]
(qvd);
ITEMS:
LOAD
ItemCode,
applymap('DESC_MAP', ItemCode, null()) as UserDesc
FROM [lib://QVData/Items.qvd]
(qvd); 

is equivalent to

select 
ItemCode,
(Select UserDescriptions.ItemName FROM UserDescriptions where Items.ItemCode = UserDescriptions.ItemNum) as UserDesc
from Items

You should be able to just paste your complicated map creation SQL queries into your CASE query logic, then you still need to add the POSTATUS_KEY to the where clause to make it return a unique line each time

answered Mar 29, 2024 at 7:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.