Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

SQL CASE in Qlik

Hello everybody,

I wanna this CASE statement translate in Qlik script.

CASE

    WHEN Kontaktfehler =1 THEN 1

      WHEN HSpgFehler =1 or HSpgFehlerW =1 THEN 2

      WHEN Weg1 =1 or Weg1W =1 THEN 3

ELSE 0

END as Errorcode,

grateful for any help

Thanks.

1 Solution

Accepted Solutions
sunny_talwar

Should be like this

If(Kontaktfehler = 1, 1,

    If(HSpgFehler = 1 or HSpgFehlerW = 1, 2,

          If(Weg1 =1 or Weg1W =1, 3, 0))) as Errorcode

Modified my expression based on Shivesh's response

View solution in original post

8 Replies
shiveshsingh
Master
Master

You can use If statement here or while loading from DB, you can use case there itself

sunny_talwar

Should be like this

If(Kontaktfehler = 1, 1,

    If(HSpgFehler = 1 or HSpgFehlerW = 1, 2,

          If(Weg1 =1 or Weg1W =1, 3, 0))) as Errorcode

Modified my expression based on Shivesh's response

Anonymous
Not applicable
Author

Thank you, it works.


Let vToday = Floor(today()-180);

ODBC CONNECT TO viebjsql_daten;

K0_K1:

Load*, If(KontaktFehler = 1, 1,

               If(HSpgFehler = 1 or HSpgFehlerW = 1, 2,

                    If(WegFehler1 =1 or WegFehler1W =1, 3, 0))) as Errorcode;

SQL SELECT *

FROM "PrfDat_ENTW".dbo."schuetzprf_K0_K1_agg1" WHERE "Prüfdatum" >$(vToday);

shiveshsingh
Master
Master

Hi Sunny

There should be a comma also after 1 and 2 to make it else if..or it will work too..


If(Kontaktfehler = 1, 1  here

    If(HSpgFehler = 1 or HSpgFehlerW = 1, 2 here

          If(Weg1 =1 or Weg1W =1, 3, 0))) as Errorcode

Anonymous
Not applicable
Author

Yes comma is needed.

sunny_talwar

Hahahaha yes, you are right... fixing my response now

shiveshsingh
Master
Master

Great

shiveshsingh
Master
Master

Glad to know it worked