Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

SQL Case Statement

Hello,

I understand that QlikView does not like MS SQL CASE statements so I am trying to work around this.  It will get more complex but I have to start getting away from the SQL way for this.  I basically want to do a select like this:

SLELECT something1, something2, ...., UseRate = CASE WHEN [UKURS] = 0 THEN 1

ELSE [UKURS]

END

This will turn all 0s to 1s....what I really want to do next is look up, in another table, an actual rate based on a different field, like a subselect.... SELECT Rate from rateTable WHERE Country = 'UK' AND Month = 4 and Year = 2015.....but I must learn to walk before I can run....

Thanks for any help,

Dave

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

David Gilligan wrote:

I understand that QlikView does not like MS SQL CASE statements so I am trying to work around this.

I've never had a problem with CASE statements in SQL SELECT. Everything after the "SQL" is passed directly to the DBMS and is not processed by QV.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

6 Replies
vikasmahajan

CASE

   WHEN condition_1 THEN result_1

   WHEN condition_2 THEN result_2

   ...

   WHEN condition_n THEN result_n

   ELSE result

END

try this

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
jonathandienst
Partner - Champion III
Partner - Champion III

David Gilligan wrote:

I understand that QlikView does not like MS SQL CASE statements so I am trying to work around this.

I've never had a problem with CASE statements in SQL SELECT. Everything after the "SQL" is passed directly to the DBMS and is not processed by QV.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Sorry Vikas, maybe I am not clear or I misunderstand you.  Can I use a CASE in SQL in QlikView...it appears to throw an error when it hits a case in a sql block...my code works perfectly in SQL Management Studio but dies when I bring it into QlikView.

Not applicable
Author

That is what I thought too....hopefully I just missed something when I copied...let me give another try but it takes a while before I will know, it is a big load but lockally only runs 1 time per day.

jonathandienst
Partner - Champion III
Partner - Champion III

Did you have a SQL before the SELECT?

To Test the SQL statement, but a TOP clause for testing

     SQL SELECT TOP 1000 ......

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Must have meen a typing mistake as it does work and the article that stated that "CASE" does not work when loading tables, actually refers to using a CASE statement in a LOAD not SQL created tables.  This is good news for me.  Thanks for the responses.