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 trying to replace selected string values in an attribute table, eg. "Text1" for "Text2" (QGIS 1.8.0), patriculary for those rows with NULL values. I have been trying to use the replace expression (and any other that I have found) with no luck.

Are there any wildcard characters that I may be able to use in future?

share|improve this question
    
check also regexp_replace() function as described in gis.stackexchange.com/questions/40637/… –  underdark Dec 3 '12 at 8:33
add comment

1 Answer 1

up vote 5 down vote accepted

You could try a case when expression:

case when "Column_1" is NULL then  replace("Column_2",'Text2','Text1') else "Column_2" end

Using the 'or' expression, you can add multiple columns with NULL-values to the code.

case when "Column_1" is NULL or "Column_3" is NULL then  replace("Column_2",'Text2','Text1') else "Column_2" end

edit:

If you want to replace NULL, forget the replace-expression (it only works for strings and NULL is no string). Try this exact code:

case when "Feature" is NULL then '12_1' else "Feature" end
share|improve this answer
    
Thanks for the fast reply. How would the 'case when' expression work when simply wanting to update values in a field, rather than creating a new field? –  mastorey Dec 2 '12 at 19:51
    
Just select the field you want in the Field Calculator instead of choosing "Create new field". The code stays the same. –  GR_ Dec 2 '12 at 19:55
    
Thanks again. I think the problem may lie in the fact that my attribute table has but one field? I am trying to update the values of selected polygons, i.e. from a NULL value to a single alphanumeric tag. Whatever, I wonder, happenned to the 'find and replace' function of earlier QGIS releases. –  mastorey Dec 2 '12 at 20:10
    
This should do the trick: case when "Column_1" is NULL then 'Text1' else "Column_1" end –  GR_ Dec 2 '12 at 20:15
    
Thanks but I'm still not getting any changes to the attribute table. Based on the code you've suggested, I'm entering the following: case when "Feature" is NULL then replace("Feature",'NULL','12_1') else "Feature" end I've also tried to express NULL as both 'NULL' and '' without success. Any further help would be very welcome and most appreciated. –  mastorey Dec 2 '12 at 20:36
show 3 more comments

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.