Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using QGIS 1.8 on windows XP machine and I try to do a concatenation of several fields to label the names of my local roads in the attribute table, but I can not find the correct syntax. The first field consists of om the street, the second type of link, eg: Avenue and the third orientation, for example, East or West. Could you tell me how to write the correct syntax using the dialog box of labels based on a formula. Attached a screenshot that shows the attribute table.

enter image description here

share|improve this question

The concatenation operator is || (odd huh?), so you would use something like:

street || ', ' || link || ', ' || orientation

Intersperse them with any separators and static strings you like.

As @NathanW noted, this will fail if any of the fields is NULL, but you can use a fallback value in that case:

street || ', ' || CASE WHEN ("link" IS NULL) THEN '(nodata)' ELSE "link" END || ', ' || orientation

QGIS supports a helper function coalesce since version 2.0. It is there to avoid the problems of NULLs and the example would look like:

 street || ', ' || coalesce(link, '(nodata)') || ', ' || orientation
share|improve this answer
There is also the concat function in the dev versions. Using || doesn't handle NULL, if link is NULL the whole label is null concat doesn't have this issue. || is taken from Postgres – Nathan W Jul 12 '12 at 12:07
Looks like it doesn't support case statements directly. Is the only option without using SQL directly to create a non-NULL copy of the link column? – lynxlynxlynx Jul 12 '12 at 12:22
What do you mean doesn't support case statements? – Nathan W Jul 12 '12 at 12:23
You are missing END. The correct string is CASE WHEN ("link" IS NULL) THEN '(nodata)' ELSE "link" END – Nathan W Jul 12 '12 at 12:48
ahh coalesce is the the one I meant. – Nathan W Jul 13 '12 at 12:37

On QGIS veriosn 2.0.1 the simple expression worked like this:

"field1" || ' (' || "field2" || ')'

desired output: field1 (field2)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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