Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

Case Statement in SQL convert to QlikView

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

 

6 Replies
rubenmarin

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)))

PrashantSangle

We can optimize it more as 

If(COLUMN1='T', 'TA'

  ,If(COLUMN2='C'

    ,If(COLUMN3='C' or COLUMN4='C', 'TR', 'TR1)))

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
rubenmarin

Indeed, just one addition:

If(COLUMN1='T', 'TA'

  ,If(COLUMN2='C'

    ,If((COLUMN3='C' or COLUMN4='C') and COLUMN1<>'T', 'TR', 'TR1')))

PrashantSangle

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.

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
rubenmarin

You are right again 😊