Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I am trying to get an IF statement working where a variable is compared against a field value. My code is:
SET MyLocalVariable = 'test';
MyTable:
LOAD Field1,
Field2,
Field3
FROM
MyTable.qvd] (qvd);
IF MyLocalVariable <> Field1 THEN
// Some more code
//...
Exit script;
END IF
Unfortunate this isn't working. In the IF statement Field1
seems to be NULL when checking in the debugger. I am sure that Field1
of the table is filled with a string value. No Unqualify is set.
How can I make this statement work, e.g. compare a variable against a field value?
Thanks,
Korrelzeep
You must use peek or fieldvalue function to get the value from a table and match it against a variable. if the table has more than one value, then you much use a for loop if you want to compare all the values.
Try something like this
SET MyLocalVariable = 'test';
MyTable:
LOAD Field1,
If(Field1=$(MyLocalVariable) , 1 , 0 ) as Flag
Field2,
Field3
FROM
MyTable.qvd] (qvd);
where you create a new field Flag = 1 if Field1='test'
regards
jjj
You must use peek or fieldvalue function to get the value from a table and match it against a variable. if the table has more than one value, then you much use a for loop if you want to compare all the values.
Hi syed.maqsood,
Thank you, that did the trick.
Regards,
Korrelzeep
Hi Jean-Jacques,
Thank you for your suggestion. Unfortunate I am not sure I can use this at this moment because is it giving me a new field which I cannot test either. I think your solution provides a new field which can be shown on a sheet. However I really need to test the condition in the script because the script must be ended when the condition is true.
Regards,
Korrelzeep