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

Find value in a field

Hi everyone,

I´d like to know how can I do to get a '0' if a value doesn´t exist in a field and a '1' if the value exist.

For example, I have this table:

T1:
LOAD * INLINE [
F1
'a'
'a'
'a'
'b'
'c'
];

And I´d like to know if 'z' value is in the F1 field, getting a '1' or a '0' if the value exist or not.

I´ve tried this

tmp:
LOAD COUNT(DISTINCT F1) as Found RESIDENT T1 WHERE F1='z';

LET value= peek('Found',0,'tmp');

But the value is NULL and not '0' when 'z' is not in the table.

Thanks a lot.

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You can change your expression to:

LET value= NoOfRows('tmp');

An easier way might be to skip creating the tmp table and use fieldIndex().

LET value = if(fieldIndex('F1', 'z') > 0, 1, 0);

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You can change your expression to:

LET value= NoOfRows('tmp');

An easier way might be to skip creating the tmp table and use fieldIndex().

LET value = if(fieldIndex('F1', 'z') > 0, 1, 0);

Not applicable
Author

Thanks a lot.