17

I am trying to write an ELSEIF conditional statement in QGIS Field Calculator (version 1.8.0). I have used an example I found online:

CASE WHEN val < 0 THEN 'negative'
 WHEN val = 0 THEN "neutral'
 ELSE 'positive'
END

I modified the statement as follows:

CASE WHEN "GRID_ID" = 1 THEN 'complete'
 ELSEIF "GRID_ID" = 2 THEN "in progress'
 ELSE 'not started'
END

This statement would not run, the Output preview stated Expression is invalid. The more info stated: Parser Error: syntax error, unexpected COLUMN_REF, expecting WHEN or ELSE or END

If anyone has had this error, what did you do to fix it?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 2, 2012 at 13:50
0

1 Answer 1

28

You have a few problems in your modified statement.

  • Inconsistent use of quotes around "in progress'
  • You don't need quotes around column names.
  • You're using an "ELSEIF" when it should be a "WHEN".

The following should resolve all three issues and works for me in 1.8.0:

CASE WHEN GRID_ID = 1 THEN 'complete'
 WHEN GRID_ID = 2 THEN 'in progress'
 ELSE 'not started'
END
answered Nov 2, 2012 at 14:16
4
  • 2
    "You don't need quotes around column names." You don't but I would still recommend it as it will help the syntax highlighter mark that part as a column. Commented Nov 3, 2012 at 1:20
  • @NathanW - the Syntax highlighter marks column names in red whether you use quotes or not, at least it does in my 1.8.0 install. Commented Nov 5, 2012 at 12:23
  • 1
    It does indeed. That is pretty embarrassing, I should have known it does that as I wrote the highlighter ;) Commented Nov 5, 2012 at 13:17
  • @NathanW - Understandable. I can barely remember what I wrote yesterday after all. ;-) Commented Nov 5, 2012 at 14:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.