Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
shmkmr90
Contributor III
Contributor III

If else clause in the script of Qlikview <Script line error>

Hi,

I'm new to Qlikview, Could anyone help me in using a 'if else' clause in the script level of Qlikview.

I want to run a SQL Query based on IF ELSE condition, the satisfied condition i want to save it in a qvd. I get a script line error as in the screen shots at IF and Else statement line. when clicked 'ok' in the error, both the SQL statements run and fetch data in Qlikview.

Example:

IF (weekday(today())='Sat')

SQL SELECT * FROM TABLE1;

ELSE

SQL SELECT * FROM TABLE2;

Here is the SQL query used in the Mysql (SQL Server) Database.

if exists (select 1 WHERE datename(WEEKDAY,GETDATE())='Monday')

SELECT * FROM  TABLE1

else

SELECT * FROM  TABLE2

Thanks for your help

Message was edited by: shyam kumar

1 Solution

Accepted Solutions
Anil_Babu_Samineni

It should be like below. Remove Parenthesis in your IF statement. Because, IF statement need two arguments

IF weekday(today())='Sat' THEN

SQL SELECT * FROM TABLE1;

ELSE

SQL SELECT * FROM TABLE2;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful

View solution in original post

6 Replies
shmkmr90
Contributor III
Contributor III
Author

I noticed a syntax error in the query which i shared earlier (Missed THEN in the example). But However when i give a table name and store it in a qvd, it is throwing an error.

Temp:

IF (weekday(today())='Sat')

SQL SELECT * FROM TABLE1;

ELSE

SQL SELECT * FROM TABLE2;

LOAD TEMP INTO TABLE.qvd;

Please Guide me. Many Thanks for your help

tresesco
MVP
MVP

Missing a 'Then'  may be?

Anil_Babu_Samineni

It should be like below. Remove Parenthesis in your IF statement. Because, IF statement need two arguments

IF weekday(today())='Sat' THEN

SQL SELECT * FROM TABLE1;

ELSE

SQL SELECT * FROM TABLE2;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
prma7799
Master III
Master III

Try like this

if.png

avinashelite

loveisfail‌ one small correction you should close the if condition

IF weekday(today())='Sat' THEN

SQL SELECT * FROM TABLE1;

ELSE

SQL SELECT * FROM TABLE2;

END IF

Anil_Babu_Samineni

Noted !! But, I don't think whether we need close IF statement like you mentioned. Tested and done. This Statement required when we having the script after that Else statement.

Thanks for correct root

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful