3

For example, Column A (1, Michigan Street, Michigan), Column B (Michigan Street) and Column C (Yes, No).

I want to use Field Calculator to update Column C in a way that it return NO if Column A contains the same street name as Column B. However, it does not work. What I tried:

Case
when "Column A" LIKE '%"Column B"%' then 'No'
else 'Yes'
end

So I try to go longer route by selecting features in Column A if it has exact words in Column B

"Column A" LIKE '%Column B%'

but it doesn't work either. Any idea on what expression to use as I don't want to write every code differently according to Column B?

3
  • Asking about "Query Builder" is misleading, as it could mean you're asking about the SQL query/provider feature builder. You are asking about QGIS expression string builder/Field calculator.
    – Babel
    Jan 6 at 11:02
  • Does the field Column A follow the pattern on something, street, something?
    – Mayo
    Jan 8 at 0:35
  • Yes. It does follow a pattern of house number, street name and district. Jan 8 at 13:43

2 Answers 2

4

The proper syntax is :

Case
when "Column A" LIKE '%' || "Column B" || '%' then 'No'
else 'Yes'
end

(You need to concatenate the column content with the '%' using the pipe operator)

Of course you also could use the alternative expression provided by @Babel

0
4

Use this expression:

case 
    when regexp_match ("Column A", "Column B") > 0
    then 'No'
    else 'Yes'
end

The function regexp_match() looks if the string of "Column B" is contained inside "Column A". It returns the position of the first character and 0 if the string is not found.

enter image description here

1
  • Thank you for the help! Jan 8 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.