Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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
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.
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
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';
Thanks, Alessandro. I am still learning which logic is applicable where!
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