Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
battistiandco
Contributor II
Contributor II

WHERE CLAUSE WITH A VARIABLE

Hi, who can help me.

I want to use a WHERE clause during a load of a file where I check a field with a variable assigned value before the script execution starts

Example: if I start in this way

qv.exe /r /vMyvar=123 abc.qvw

let Myvar = '';

load Field1,

        Field2

[from c:\tmp\Test.txt]

WHERE (Field1 = Myvar);

But an error occurs during the load. It don't recognise the variable Myvar

1 Solution

Accepted Solutions
rbecher
MVP
MVP

Hi,

try this:

1. don't set the variable in the script to an empy value (let Myvar = '';)

2. use right notation in Where Clause:

WHERE (Field1 = $(Myvar));  // on numeric value

WHERE (Field1 = '$(Myvar)');  // on string value

- Ralf

Astrato.io Head of R&D

View solution in original post

5 Replies
rbecher
MVP
MVP

Hi,

try this:

1. don't set the variable in the script to an empy value (let Myvar = '';)

2. use right notation in Where Clause:

WHERE (Field1 = $(Myvar));  // on numeric value

WHERE (Field1 = '$(Myvar)');  // on string value

- Ralf

Astrato.io Head of R&D
whiteline
Master II
Master II

The string "let Myvar = ''; " in your script erases the value. Remove It.

battistiandco
Contributor II
Contributor II
Author

Thank, Great Ralf

Rainer

sudeepkm
Specialist III
Specialist III

Hi Ralf,

Is it possible to load field values of a table to a variable and then use the variable in the load script where clause like below.

filtertab:

load * Inline [

code

dd

mm

];

MainDatatab:

LOAD ID,

     Date,

     City,

     CityCode

FROM

<some table>

where not match(CityCode,'dd','mm');

In the above scenario I would like to update the where clause to exclude the values of CityCode with the values of the field code (from table filtertab) instead of hard coding the values in the where clause.

rbecher
MVP
MVP

Hi Sudeep,

this would be possible but why not simply using exists() here?

MainDatatab:

LOAD ...

WHERE not exists(code, CityCode)

- Ralf

Astrato.io Head of R&D