Announcements
cancel
Showing results 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
MVP

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

8 Replies
Master

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

MVP

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:

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

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.

MVP

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

Master

Great

Master