Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
BasharSalloum
Contributor
Contributor

Qlik Sub-routine to load table

Hi community

Your kind help in below issue is highly appreciated...

 

I have created a sub routine to load a table from database , my sub. looks like:

////// Sub routine to load Qlik table based on sql query

Sub loadFromDb(vTableName, vDbQuery)

$(vTableName):

SQL $(vDbQuery)

STORE $(vTableName) INTO [lib://$(vTableName).qvd] (qvd);

DROP TABLE$(vTableName);

End Sub

//////////////////End code/////////

 

I am calling this sub by:

 

////// Calling sub

Let query="select field1, field2 from tableName"

call loadFromDb('qlikTableName', $(query))

////// End calling sub

 

I am always getting the error "Unknown statement: :select field1, field2 from tableName",

The same code is working fine if not using subroutine 

 

Can you please help me in knowing the cause of this error,

Thanks a lot

 

 

 

1 Solution

Accepted Solutions
rubenmarin

Hi, that simle quotes are neede so maybe there is some other place where youneed to use them, which line returns the error? You can addd 'TRACE' sentences to check where it stops.

Some other changes, like using set instead of let, and add missing semicolons.

////// Sub routine to load Qlik table based on sql query
Sub loadFromDb(vTableName, vDbQuery)
$(vTableName):
SQL $(vDbQuery);
STORE $(vTableName) INTO [lib://$(vTableName).qvd] (qvd);
DROP TABLE$(vTableName);
End Sub
//////////////////End code/////////
 
////// Calling sub
Set query=select field1, field2 from tableName;
call loadFromDb('qlikTableName', $(query))
////// End calling sub

 

View solution in original post

4 Replies
rubenmarin

Hi, try addding simple quotes to the query:

call loadFromDb('qlikTableName', '$(query)')

SalloumBashar
Contributor
Contributor

Thank you for ur reply , adding single quotes to the variable changed nothing , i am still getting the same behavior.  

rubenmarin

Hi, that simle quotes are neede so maybe there is some other place where youneed to use them, which line returns the error? You can addd 'TRACE' sentences to check where it stops.

Some other changes, like using set instead of let, and add missing semicolons.

////// Sub routine to load Qlik table based on sql query
Sub loadFromDb(vTableName, vDbQuery)
$(vTableName):
SQL $(vDbQuery);
STORE $(vTableName) INTO [lib://$(vTableName).qvd] (qvd);
DROP TABLE$(vTableName);
End Sub
//////////////////End code/////////
 
////// Calling sub
Set query=select field1, field2 from tableName;
call loadFromDb('qlikTableName', $(query))
////// End calling sub

 

BasharSalloum
Contributor
Contributor
Author

Thank you so much , removing the quotes , and replacing Let with Set solved the problem