2

I've got a Shapefile containing contourlines which I would like to style differently according to their value. For that reason I created a field named "100s" where I would like to give values from 0=25m-lines, 1=100m-lines and 2=500m-lines. For doing that I tried the "replace" function with this syntax:

NAME="4600" OR NAME="4700" OR NAME="4800"  replace('NULL','NULL','1')

but QGIS gives the following error: "syntax error, unexpected FUNCTION, expecting $end". When I then set "$end, the error message is the same. Any suggestions how to resolve that? Thanks in advance, Ralf

1 Answer 1

2

It's giving you that error because it's the wrong syntax. The OR and AND keywords return true or false. The replace function is for strings so you don't really need it here. What you are looking for is the case expression:

CASE WHEN NAME="4600" OR NAME="4700" OR NAME="4800" THEN 1 END

Note: You need to be running the dev build of QGIS to get that function

4
  • 2
    CASE WHEN expressions seem to be working with 1.8. as well. Either that or I am using a devbuild in disguise...
    – GR_
    Dec 10, 2012 at 9:32
  • They might work in 1.8 I lost track when they were added.
    – Nathan W
    Dec 10, 2012 at 9:46
  • Hello Nathan,thank you very much! I tried this solution after installing the latest version but infact I didn't get that function. Since I'm running a MAC I looked for the dev build at kynchaos but I wasn't shure which one to choose ... could you please provide a link to the working version? Thanks again, Dec 10, 2012 at 10:37
  • I just checked.. CASE WHEN works on 1.8 under Mac.
    – GR_
    Dec 10, 2012 at 11:05

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.