Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
tom2qlik
Creator
Creator

SQL within Script IF Statement Error


Hello,

I am having an issue with a little script I'm writing. 

I'm extracting data from database tables using SQL, and I would like to apply a condition to only 1 table from this list.

For some reason Qlikview does not like my else statement as that's where it's breaking.

I have not written an IF statement containing SQL before so it's a first for me.

Any help would be appreciated.

Thanks,

Tom


For i = 0 To $(vTableCount)
Let vCurrentTable = Peek('TableName', $(i), 'SQLTableList');

if $(vCurrentTable) = 'SAMPLE_RESULT' THEN
$(vTableCount):

SQL SELECT * FROM [lvl].[dbo].$(vCurrentTable)
WHERE Date(EntryDt, 'DD/MM/YYY') >= '01/01/2010';

ELSE 
$(vTableCount):
SQL SELECT * FROM [lvl].[dbo].$(vCurrentTable);


STORE $(vCurrentTable) into $(vDatasource)$(vCurrentTable).QVD(qvd);
DROP Table $(vCurrentTable);
NEXT i;



1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

Hi Tom,

You're missing an END command to that IF statement.

You could also just set a date variable to use in a single SQL code instead of writing the full code - this just seems a cleaner option. Just set the date in the where clause to something like'01/01/1900' to select everything and place that outside the IF..ELSE..END command.

flipside

View solution in original post

1 Reply
flipside
Partner - Specialist II
Partner - Specialist II

Hi Tom,

You're missing an END command to that IF statement.

You could also just set a date variable to use in a single SQL code instead of writing the full code - this just seems a cleaner option. Just set the date in the where clause to something like'01/01/1900' to select everything and place that outside the IF..ELSE..END command.

flipside