Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Missing Parenthesis in SQL IF Statement?

Hi All,

Not sure what I am missing here in my Sql Statement. I keep getting the [Error] Execution: (ORA-00907: missing right parenthesis error

LOAD

  *;

SQL select

     fact.TRANSACTION_TYPE_ID,

    fact.TRANSACTION_DATE_ID,

    fact.TRANSACTION_ID,

    fact.MATERIAL_ID,

   IF(detail.Order_Type = 'FOR','1','2') as FOR_TYPE_ID,

     fact.BACKLOG_QUANTITY

from BACKLOG_WEEKLY_FACT_MV fact,

     BACKLOG_HISTORY_MV detail

where fact.TRANSACTION_ID = detail.BACKLOG_HISTORY_ID;

Any help will be appreciated.

Thanks in advance,

Archie

1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

Try using a case statement instead of the if statement ...

CASE WHEN detail.Order_Type = 'FOR' THEN '1' ELSE '2' END as FOR_TYPE_ID,

flipside

View solution in original post

8 Replies
PrashantSangle

Hi,

If possible Can you post screen shot of your error???

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable
Author

3-25-2014 10-44-33 AM.jpg

Not applicable
Author

Why dont you try Prelaod and do all calculations/joins in QV script rather than in SQL script.

ex:

Load *, IF(match(Order_Type =,'FOR','1','2'),Order_Type ) as FOR_TYPE_ID;

SQL Select *

From Detail;

Inner Join

Load *;

SQL Select *

From Fact;

I used * but you should use only the fields you want.

Thanks

AJ

PrashantSangle

Hi,

Several Possibilities,

Like

1> Try your select statement without If statement.

2>Try to give alise name for FOR_TYPE_ID i.e. it is coming from "detail" or "fact"

in your if expression IF(detail.Order_Type = 'FOR','1','2') as FOR_TYPE_ID,


Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
flipside
Partner - Specialist II
Partner - Specialist II

Try using a case statement instead of the if statement ...

CASE WHEN detail.Order_Type = 'FOR' THEN '1' ELSE '2' END as FOR_TYPE_ID,

flipside

Not applicable
Author

That should work, though I usually bring in everything to a QVD then do the transformation in the Load Script of the Qvw.

Far easier scripting in Qlikview !

flipside
Partner - Specialist II
Partner - Specialist II

I agree, but I always find it is useful to know the proper logic in case I do need it later !

Not applicable
Author

Thanks so much!

The Case Statement did the trick

Appreciate your help.