I am facing challenges in using the Left join. Simple inner join is working fine
Table Result1 = Table.query("SELECT PersonSalary.Person, PersonSalary.Salary,PersonAllowance.Allowance FROM PersonSalary INNER JOIN PersonAllowance ON PersonSalary.Person = PersonAllowance.Person"); Table Final1 = Result1.cloneTo(Table("Result1"));
When I try to use left join. The flexsim is throwing exception error.
I want to have all the rows of PersonSalary table. If there is no allowance for that person the column allowance should show "No allowance".
Code used for the above requirement is
Table Result2 = Table.query("SELECT PersonSalary.Person, PersonSalary.Salary, CASE WHEN PersonAllowance.Allowance IS NULL THEN $1 ELSE PersonAllowance.Allowance END AS Allowance FROM PersonAllowance LEFT JOIN $1 ON PersonSalary.Person = PersonAllowance.Person","NoAllowance"); Table Final2 = Result2.cloneTo(Table("Result2"));
Expected output:
Person | Salary | Allowance |
A | 100 | 10 |
B | 200 | 20 |
C | 300 | 30 |
D | 400 | "No Allowance" |
E | 500 | "No Allowance" |
Please find the attached Flexsim model for the same.
Thanks in advance.