Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Not applicable

My way of writing CASE WHEN ELSE statement

Question: How to write the following T-SQL statement in Qlik?

SELECT

MyNumber,

CASE

WHEN MyNumber = 1 THEN 'One'

WHEN MyNumber = 2 THEN 'Two'

ELSE 'Three or more'

END AS MyText

FROM ...

Syntax:

Using PICK and MATCH functions with a value of TRUE to compare with:

PICK (MATCH (-1, Condition1, Condition 2, -1), Result1, Result2, Default Result)

Solution:

LOAD

MyNumber,

PICK ( MATCH (-1, MyNumber = 1, MyNumber = 2, -1), 'One', 'Two', 'Three or more') AS MyText

FROM ...

Please let me know your opinion about it, or if you have a better way for writing that.

If you want to check, just copy and paste the following:

LOAD *, PICK ( MATCH (-1, MyNumber = 1, MyNumber = 2, -1), 'One','Two','Three or more') AS MyText;

LOAD * INLINE [MyNumber

1

3

5

4

2

7

9

];

1 Solution

Accepted Solutions
MVP
MVP

Re: My way of writing CASE WHEN ELSE statement

PICK ( WILDMATCH (MyNumber, 1, 2, '*'), 'One','Two','Three or more') AS MyText

7 Replies
MVP
MVP

Re: My way of writing CASE WHEN ELSE statement

PICK ( WILDMATCH (MyNumber, 1, 2, '*'), 'One','Two','Three or more') AS MyText

Not applicable

Re: My way of writing CASE WHEN ELSE statement

That makes it easier.

Thank you

MVP
MVP

Re: My way of writing CASE WHEN ELSE statement

could you close the thread? thanks

Not applicable

Re: My way of writing CASE WHEN ELSE statement

Sorry I don't know how to close a thread. Please advise

oknotsen
Honored Contributor III

Re: My way of writing CASE WHEN ELSE statement

You do so by flagging the correct answer as "Correct Answer".

But for that to be an option, you need to start a question as a question to begin with; you started a discussion.

I have converted it to a question and you can now mark the Correct Answer.

Onno

Community Team member

May you live in interesting times!
MVP
MVP

Re: My way of writing CASE WHEN ELSE statement

Ops, I didn't know this (Correct Answer only for question) difference; thanks for the explanation.

oknotsen
Honored Contributor III

Re: My way of writing CASE WHEN ELSE statement

Happy I could help and having the rare opportunity to learn a MVP something new .

May you live in interesting times!
Community Browser