2

I have edited a cvs/xls (2003 format) file to make sure certain columns are split in two, so I could make two drop down list filtered to each other. At least that was the plan, I have not done this yet. Now it is just some text string, so all the points of my shapefile what the table could have been joined to are filled in. But considering I am gonna create some database trigger, I want it back to the way it was before.

This is what it was originally:

enter image description here

And now it is like this

Column1-Colunm2

Begeleidingsnoei-Extra

Now I want to have it back like the original. Written out the same like that.

How do I do this?

Edit: I tried to use the case expression but no matter what this happens:

enter image description here What I am doing wrong here?

enter image description here

Edit 2: Even using Case Null has the same effect.

enter image description here

  • can you add the actual expression you used – Ian Turton Mar 29 '17 at 13:08
  • Added the case expresion screenshot – ThunderSpark Mar 29 '17 at 13:15
  • @ThunderSpark - Are there NULL values in your field? In which case, you could try replacing CASE WHEN "LCSTE" = '' with CASE WHEN "LCSTE" IS NULL. – Joseph Mar 29 '17 at 13:20
  • Nope even when I use you Null case, still nothing. – ThunderSpark Mar 29 '17 at 13:25
  • I have edited my post the same problem occurs even using the NULL CASE. – ThunderSpark Mar 30 '17 at 9:46
2

Try using + for string concatenation (it works since QGIS 2.6) instead of the || you are using. The + string concatenation deals with the NULL value. So that would be:

"column1" + ' - ' + "column2"

You should also check the output field type to be string and the output field length to be enough for the concatenation.

  • Oke that worked now I need to deal with - in the empty value's and where I did not want a -. A simple replace can normaly fix that I think. – ThunderSpark Mar 30 '17 at 11:07
  • Glad it worked. Use the case statements as you mentioned before and I believe you'll get what you want. If you have null values only in the column2 you could create a new column3 and concatenate ' - ' +"column2" and then do "column1" + "column3" – geoSAM Mar 30 '17 at 11:21
4

You need the string concatenation operator || so

"Column1" || '-'|| "Column2"

For the more complex case where sometimes there is no 2nd column use a case statement.

CASE WHEN  "Column2" = '' 
  THEN "Column1"
  ELSE "Column1" || '-'|| "Column2"
END
  • By creating then a new column in the field calculator or does it automatically merge the two columns? – ThunderSpark Mar 29 '17 at 12:04
  • no that needs to be a new column if you want to save it – Ian Turton Mar 29 '17 at 12:04
  • Ok that works the only problem Inow have is that the new column then only contains value's for example Vormsnoei-knotten for example. And not value's like Vormsnoei were there was no value in the second column. How do I fix that? – ThunderSpark Mar 29 '17 at 12:12
  • I edited my post, since no matter if I use the case expression it stil goes wrong. – ThunderSpark Mar 29 '17 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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