1

First of all, sorry, I couldn't phrase my question better.

So I want to be able to add a new column in my attributes table, say B, and it's value should be 1 if Column A's value is 1 and 0 if Column A's value is 2. in other words:

If A==1 : B=1

elif A==2 : B=2 I couldn't figure out a way to do this using Field Calculator.

Thanks Trying to update "MineDeleteIt" values based on path_type

  • After the THEN it should be 'Bike lane baby' and also 'some arbitrary text'. You need single quotes for strings – Nathan W Jan 23 '13 at 4:36
  • You are right. I had added double quotes and it didn't make any difference. Thanks a lot for your patience! – Alex Jan 23 '13 at 4:39
  • 1
    Double quotes are for column names. Single quotes for strings. – Nathan W Jan 23 '13 at 4:43
  • @NathanW Sorry for pushing this, but do if-else conditions work too? I'm getting errors, but if it's possible I'll figure it out myself... – Alex Jan 23 '13 at 4:50
  • 1
    Not yet. We haven't added support yet. Feel free to open at ticket at hub.qgis.org and assign it to me. I'm the only Nathan in the list. – Nathan W Jan 23 '13 at 5:07
3

You can use a case statement to do that:

CASE 
    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2 
END

If you want everything else to match you can use ELSE

CASE 
    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2
    ELSE 0
END

This way everything that is not A=1 or A=2 will get assigned 0.

  • thanks for your answer. Can you tell me where should I enter it though? should I use field Calculator? Because it says invalid expression... – Alex Jan 22 '13 at 21:49
  • Which version of QGIS? – Nathan W Jan 23 '13 at 0:35
  • it's 1.8. are u able to do it with field calculator? – Alex Jan 23 '13 at 1:37
  • Yes. What does it say when you click (More INfo) – Nathan W Jan 23 '13 at 3:56
  • it say's : Parser Error: syntax error, unexpected COLUMN_REF, expecting WHEN or ELSE or END Eval Error: No root node! Parsing failed? – Alex Jan 23 '13 at 4:13

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.