Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

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

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

Re: SQL Case Statement

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
6 Replies
vikasmahajan
Esteemed Contributor

Re: SQL Case Statement

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

MVP
MVP

Re: SQL Case Statement

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

Re: SQL Case Statement

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

Re: SQL Case Statement

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.

MVP
MVP

Re: SQL Case Statement

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

Re: SQL Case Statement

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.

Community Browser