I am trying to compare the values of 2 fields in my attribute table and update a 3rd field as a result. In the field calculator I have
CASE when (("Address") like ("COUNTYNAME" )) then 'Match'
else 'Error'
End
so for the following toy data examples I would get the result Match,Error,Error
Address,COUNTYNAME
- Smith, Smith County
- Bob, Smith County
- Jane, Bob County
I have also tried CASE when (("Address") IN ("COUNTYNAME" )) then
Are there any other ways to compare text values within QGIS?
Best Answer
You can do something like this to compare two fields together:
The
strpos()
function will return the index position of the first ' ' (space) character and theleft()
function "trims" the string before that position. The-1
is to ensure that the space will not be included when doing comparison.Here is the output of the above expression: