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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Concatenate SQL string with variables and special characters

Hi everyone,

I am want to feed the following query with content via variables in the load script:


SELECT

  $(vSQL_Columns)

FROM

  $(vDatabase)$(vTableName)

  $(vJoinStatement)

WHERE

  $(vWhereClause_fin)

  $(vIncrementalDate) < '$(vPrevMthStart)';


This is all straight forward until I want to parse the $(vWhereClause). The where-clause obviously contains special characters like <, > and =.


vWhereClause_fin is populated and assembled as follows. It should translate into "T1.Column1 < 14 and T1. Column1 > 15 AND".

LET vWhereClause="T1.Column1 " & chr(60) & " 14 AND T1.Column1 " &chr(62) & " 15";
LET vWhereClause_fin=If($(vWhereClause)="","",$(vWhereClause) & " AND ");
LET vWhereClause_fin=If($(vDebug)=1,$(vWhereClause_fin) & $(vDebugWhereClause) & " AND ",$(vWhereClause_fin));


As soon as I try that, I get a script error in return. What am I missing?


Thanks for your time and help!


Henning

1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

Use single quotes when referring to string variable

LET vWhereClause="T1.Column1 " & chr(60) & " 14 AND T1.Column1 " &chr(62) & " 15";
LET vWhereClause_fin=If($(vWhereClause)="","",'$(vWhereClause)' & " AND ");
LET vWhereClause_fin=If($(vDebug)=1,'$(vWhereClause_fin)' & '$(vDebugWhereClause)' & " AND ",'$(vWhereClause_fin)');
Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

2 Replies
vinieme12
Champion III
Champion III

Use single quotes when referring to string variable

LET vWhereClause="T1.Column1 " & chr(60) & " 14 AND T1.Column1 " &chr(62) & " 15";
LET vWhereClause_fin=If($(vWhereClause)="","",'$(vWhereClause)' & " AND ");
LET vWhereClause_fin=If($(vDebug)=1,'$(vWhereClause_fin)' & '$(vDebugWhereClause)' & " AND ",'$(vWhereClause_fin)');
Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Not applicable
Author

Lovely, thank you!