Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
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
Valued Contributor II

Re: Missing Parenthesis in SQL IF Statement?

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

8 Replies

Re: Missing Parenthesis in SQL IF Statement?

Hi,

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

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Not applicable

Re: Missing Parenthesis in SQL IF Statement?

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

Not applicable

Re: Missing Parenthesis in SQL IF Statement?

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

Re: Missing Parenthesis in SQL IF Statement?

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.
flipside
Valued Contributor II

Re: Missing Parenthesis in SQL IF Statement?

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

Re: Missing Parenthesis in SQL IF Statement?

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
Valued Contributor II

Re: Missing Parenthesis in SQL IF Statement?

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

Not applicable

Re: Missing Parenthesis in SQL IF Statement?

Thanks so much!

The Case Statement did the trick

Appreciate your help.

Community Browser