Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I've the below case statement in SQL and I would like to convert it into QlikView.
CASE WHEN A.COLUMN1='T' THEN 'TA' ELSE
CASE WHEN B.COLUMN2='C' THEN
CASE WHEN B.COLUMN3 = 'C' AND A.COLUMN1<>'T' THEN 'TR' ELSE 'TR1' END ELSE
CASE WHEN C.COLUMN4 = 'C' AND A.COLUMN1<>'T' THEN 'TR' ELSE 'TR1' END END END AS NewColumn
Hi, A, B and C are differnt tables, you first have to make the relations to have all needed fields in the same table. Or use ApplyMap to retrieve the values from other tables.
Once you have all in one table, you can just do it with If's, like:
If(COLUMN1='T', 'TA'
,If(COLUMN2='C'
,If(COLUMN3='C' and COLUMN1<>'T', 'TR', 'TR1)
,If(COLUMN4='C' and COLUMN1<>'T', 'TR', 'TR1)))
We can optimize it more as
If(COLUMN1='T', 'TA'
,If(COLUMN2='C'
,If(COLUMN3='C' or COLUMN4='C', 'TR', 'TR1)))
Regards,
Prashant Sangle
Indeed, just one addition:
If(COLUMN1='T', 'TA'
,If(COLUMN2='C'
,If((COLUMN3='C' or COLUMN4='C') and COLUMN1<>'T', 'TR', 'TR1')))
you don't need to add and COLUMN1<>'T' this condition in 3rd If statement, as we are already testing it in 1st if statement & if it is not validating that condition then only it will go into else part. so, it will automatically get validated.
You are right again 😊