QGIS – Label Containing Multiple Fields

expressionfields-attributeslabelingqgisqgis-3

I found this question and the anwser did help me somewhat. But my ''code'' for the label seems to have some sort of error. It won't show any label when I apply it. I've tried the following examples to try and get it to work:

Try 1
Try 2
Try 3

Does anyone have advice for me to try and make a working label? I'm not very wellversed in making codes/rules like this.

Edit:
enter image description here

Best Answer

Use concat() function. It ignores NULL values and returns an empty string '' instead of NULL and therefore gives you a result if one or more fields are NULL. This is not the case for || concatenator. || returns NULL as result if at least one field/value is NULL.

Use concat the following:

concat("myfield_a",'my string a',"myfield_b",' --> ',NULL,"myfield_c",'blablabla')

To skip concatenations of empty fields, e.g. concat("field_a",' is empty') you can use a simple if() statement: concat("field_a", if("field_a" is null,'',' is empty')) or coalesce() together with ||: concat(coalesce("field_a"||' is empty'),'',"field_b", ' is never empty')