I have two columns in my QGIS attribute table. The first column contains values that aren't contained the second column and vice versa. I would like to add a new field that contains both the values from the first and second column. I thought it might be as simple as "Value 1 + Value 2) but this just gives me Null results. All values are strings.
Value 1| Value 2 | New Column
-------------------------
Bacon | | Bacon
Eggs | | Eggs
| Cheese | Cheese
| Ham | Ham
Answer
Many operators and functions in SQL (and therefore expressions) return NULL
if one of the parameters was NULL
The following examples demonstrate the behavior of various operators on a layer with the columns A
and B
.
NULL + 'text'
➝NULL
'a' + 'b'
➝'ab'
NULL || 'text'
➝NULL
'a' || 'b'
➝'ab'
CONCAT(NULL, 'text')
➝'text'
CONCAT('a', 'b')
➝'ab'
COALESCE(NULL, 'text')
➝'text'
COALESCE('a', 'b')
➝'a'
COALESCE('a', NULL)
➝'a'
COALESCE(NULL, NULL, 'Other')
➝'Other'
In your case you want to work with either CONCAT
or COALESCE
depending on the expected behaviour with multiple / no values.
No comments:
Post a Comment