Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

1 Solution

Accepted Solutions
alexandros17
Partner - Champion III

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

View solution in original post

6 Replies
alexandros17
Partner - Champion III

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

Not applicable
Author

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.

alexandros17
Partner - Champion III

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

jmmayoral3
Creator

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';

Not applicable
Author

Thanks, Alessandro.  I am still learning which logic is applicable where!

marleygt
Creator

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