1

I am new to QGIS. This question about how to use the field calculator, because the procedure to replace all fields is explained very nicely in Replacing all null values from attribute table with zeros using QGIS?

I have the null features selected, but now I am struggling to find a means to change all of them to "no" instead of the "0".

Can someone help?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Papayapap
  • 269
  • 1
  • 4
  • 12

1 Answers1

7

Update your column using the following "code" in the field calculator

CASE WHEN "field" IS NULL THEN 'no' ELSE "field" END

This doesn't even need you to select all NULL-values beforehand - and requires your column to not to be of any numerical data type.

Erik
  • 16,269
  • 1
  • 24
  • 43
  • 3
    Alternative: if( "field" IS NULL, 'no', "field"). Yours is of course more descriptive. :) – StefanBrand_EOX Nov 27 '18 at 08:46
  • Thanks Erik and Stefan, and for the "field" I should put the name of my variable without the quotations, yes? – Papayapap Nov 27 '18 at 08:50
  • 1
    I usually use CASE WHEN because I find it easier to nest. – Erik Nov 27 '18 at 08:50
  • "field" is you columns name - and you have to use the quotation marks. Column names are always refered to by double quotation marks, values (especially strings) by single quotation marks. – Erik Nov 27 '18 at 08:52
  • That's good to know, thanks. For me the code doesn't work. I put it in the field calculator, replaced the column name, and checked the "update existing field option" but when I click on "ok" nothing happens. Do you have an idea what is happening? – Papayapap Nov 27 '18 at 09:01
  • What data does this column contain? – Erik Nov 27 '18 at 09:06
  • It is string and it contains many 'Null' and a couple 'yes' – Papayapap Nov 27 '18 at 09:07
  • Are the 'Null' values grey, or rather black and distinct? – Erik Nov 27 '18 at 09:13
  • They are white and only appear when I click on the field. – Papayapap Nov 27 '18 at 10:33
  • Does the preview provided by the field calculator at the bottom left corner of the window when you entered the code look okay? – Erik Nov 27 '18 at 11:03
  • The preview field calculator doesn't give problems. It says "Output preview: 'no'". I wanted to send you some screenshots via message but I didn't find how to send you a private message. Is this possible? – Papayapap Nov 29 '18 at 06:14
  • Just add the screenshots via an external uploadservice to your post. This way everybody else can help, too. – Erik Nov 29 '18 at 12:22
  • doing this using the QGIS db manager causes it to crash – user32882 Apr 22 '19 at 08:27