Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewwizard
Master II
Master II

SQL Conversion into Qlikview script

Hi All,

Please help in conversion of the below SQL code into Qlikview Script.

SELECT E4.EMPNO,E4.ENAME,E4.SAL+ISNULL(E5.SAL,0)+ISNULL(E8.SAL,0) AS TOTALSAL FROM EMP E4 LEFT OUTER JOIN (SELECT MGRNO,MGRNAME,SAL FROM

(SELECT M.EMPNO AS MGRNO,M.ENAME AS MGRNAME,E.EMPNO,E.ENAME FROM EMP E LEFT OUTER JOIN EMP M ON E.MGR=M.EMPNO) AS E1 INNER JOIN

(SELECT EMPNO,SAL FROM EMP WHERE LAST_DATE IS NOT NULL AND START_DATE>LAST_DATE) AS E2 ON E1.EMPNO=E2.EMPNO) AS E5

ON E4.EMPNO=E5.MGRNO

LEFT OUTER JOIN (

SELECT E6.MGRNO,E6.MGRNAME,SAL FROM

(SELECT M11.EMPNO AS MGRNO,M11.ENAME AS MGRNAME,E11.EMPNO,E11.ENAME FROM EMP E11 LEFT OUTER JOIN EMP M11 ON E11.MGR=M11.EMPNO) AS E6 INNER JOIN

(SELECT MGRNO,MGRNAME,SAL FROM

(SELECT M.EMPNO AS MGRNO,M.ENAME AS MGRNAME,E.EMPNO,E.ENAME FROM EMP E LEFT OUTER JOIN EMP M ON E.MGR=M.EMPNO) AS E1 INNER JOIN

(SELECT EMPNO,SAL FROM EMP WHERE LAST_DATE IS NOT NULL AND START_DATE>LAST_DATE) AS E2 ON E1.EMPNO=E2.EMPNO) E7

ON E6.EMPNO=E7.MGRNO) AS E8 ON E4.EMPNO=E8.MGRNO


Source data:

     

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNOSTART_DATELAST_DATE
7369SMITHCLERK790217-Dec-1980800NULL2015-May-201512-May-2015
7499ALLENSALESMAN769820-Feb-198116003003015-May-2015NULL
7521WARDSALESMAN769822-Feb-198112505003015-May-2015NULL
7566JONESMANAGER78392-Apr-19812975NULL2015-May-2015NULL
7654MARTINSALESMAN769828-Sep-1981125014003014-May-201516-May-2015
7698BLAKEMANAGER78391-May-19812850NULL3014-May-2015NULL
7782CLARKMANAGER78399-Jun-19812450NULL1014-May-2015NULL
7788SCOTTANALYST75669-Dec-19823000NULL2014-May-2015NULL
7839KINGPRESIDENTNULL17-Nov-19815000NULL1014-May-2015NULL
7844TURNERSALESMAN76988-Sep-1981150003014-May-2015NULL
7876ADAMSCLERK778812-Jan-19831100NULL2014-May-2015NULL
7900JAMESCLERK76983-Dec-1981950NULL3014-May-2015NULL
7902FORDANALYST75663-Dec-19813000NULL2014-May-2015NULL
7934MILLERCLERK778223-Jan-19821300NULL1014-May-201512-May-2015



Thanks in advance.


1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try Self join

Self join

Regards,

Jagan.

View solution in original post

8 Replies
anbu1984
Master III
Master III

You can directly run the Sql as is in Qlikview. Why do you want convert Sql into Qlikview script?

qlikviewwizard
Master II
Master II
Author

Dear anbu1984

Actually the data is coming from flat files or QVDs.

Can I use as it is? Please advise.

anbu1984
Master III
Master III

In that case you have to write Qlikview script. Can you explain what are you trying to accomplish? Why do you have same code twice in Left outer join?

Peter_Cammaert
Partner - Champion III
Partner - Champion III

It would certainly be more efficient to translate your intention into a LOAD SCRIPT. Can you describe what should happen to the source data when you load it into QlikView?

Peter

qlikviewwizard
Master II
Master II
Author

Hi anbu1984 and pcammaert,

If START_DATE>LAST_DATE then EMP SAL should allot to his/her MGR (Managers)

For example SMITH manager is FORD (7902) and his manager is JONES (7566) . So SAL should add to these two managers as START_DATE>LAST_DATE for SMITH.

Even for MILLER also need to send his SAL (1300) to his managers CLARK and his manager KING.

Please advise.

anbu1984
Master III
Master III

Check this app

engishfaque
Specialist III
Specialist III

Dear Wizard,

This is great question, I'm also looking for answer for that kind of question means SQL Query to QlikView Script conversion.

Kind regards,

Ishfaque Ahmed

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try Self join

Self join

Regards,

Jagan.