Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
share|improve this answer
2  
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 postgresql.org/docs/9.1/static/functions-string.html –  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
3  
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
1  
ahh coalesce is the the one I meant. –  Nathan W Jul 13 '12 at 12:37
show 3 more comments

On QGIS veriosn 2.0.1 the simple expression worked like this:

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

desired output: field1 (field2)

share|improve this answer
add comment

Your Answer

 
discard

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.