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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
achakilam1022
Creator II
Creator II

Multiple values from variable in where condition in SQL query

Hi all,

I have a variable vField . Its value is  'a','b','c','d'

How do I write a SQL query to check where field matches any values (a or b or c or d) in vField variable?


Thanks!

LIB CONNECT TO database1;

Table1:

Load Field,

1 as PlaceHolder;

select distinct Field from db1.xyz

where ....

;

Table2:

load

Concat(chr(39)&Field &chr(39),',') as Field_new

Resident Table1

Group by PlaceHolder;

Drop Table Table1;

let vField = Peek('Field_new', 'Table2');

Drop Table Table2;

LIB CONNECT TO database2;

Data:

Load *;

sql select * from

db2.abc

where Field_table2 in $(vField)

11 Replies
achakilam1022
Creator II
Creator II
Author

that works. thanks!

Sai78
Contributor III
Contributor III

Hi,

I have a similar situation that variable is holding no value .. when executing the script  I get error Error in 'expression:
WildMatch takes at least 2 parameters'

temp1:

load Concat(DISTINCT Chr(39)& columnname&Chr(39),',') as columnnameList

Resident Temp;

drop Table Temp;

let vVar11=peek('columnnameList',0,'temp1');
set List=$(vVar11);

test:
NoConcatenate
LOAD DISTINCT
column1,
Resident maintable
where wildmatch(columnname, $(List));---the script is failing at below condition

Any insight would be greatly appareciated.