
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how do I use exists() in if.then.else expression?
I want to conditionally load data based on whether a specific value has already been loaded.
In a Where clause I would use: where exists(fieldname, 'value')
But I want to do
IF exists(fieldname,'value')
THEN
LOAD ...
ENDIF
- Tags:
- scriptexpression
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're right but you know if a field has a certain value only when you load it and the quickest way is to load the table for that value ... I think there are not other options


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
exists must be used in a Load instruction because it check every row, to execute your condition you shoul have to load the table with a where condition on that value, then if there are rows (so the value exists) you can do the following Load
Hope I've been clear

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Seems a complicated method. Is there a succinct way to phrase it? Ideally I want to set a variable on the existence or not of the value.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're right but you know if a field has a certain value only when you load it and the quickest way is to load the table for that value ... I think there are not other options


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to load only rows when the condition was true, you don´t have to use
IF exists(fieldname,'value')
THEN
LOAD ...
ENDIF
You have to use
LOAD .....
FROM (OR RESIDENT....)
WHERE fieldname='value';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Alessandro. I am still learning which logic is applicable where!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Peter!
I met a similar situation on my last job, where I need to load for several customers with different data (especially in area code and sales agents) and I solved this way:
I set a couple of Variables - generic - and then I just use IF condition for uploading.
IF(vSetProvince=P) THEN
TableFact:
LOAD data1,
data2,
data3,
...
FROM
[File Qvd\FactsTable1.qvd]
(qvd);
ELSE
TableFact2:
LOAD data1,
data2,
data3,
...
FROM
[File Qvd\FactsTable2.qvd]
(qvd);
ENDIF
Hope this could help!
BR
Alex
