2

I can't seem to be able to troubleshoot my expression here. I'm trying to calculate a new field. Column "FOO_U_CODE" contains numerous 4 digit codes, the new column I want to create is a simplified version based on the first character of the code in "FOO_U_CODE".

I saw somewhere that you can use % to specify anything after one or multiple characters. Is it right?

What is wrong here?

   CASE
    WHEN "F00_U_CODE" IS'1%' THEN "Utilisatio"  = 'Residentiel'
    WHEN "F00_U_CODE" IS'2%' THEN "Utilisatio"  = 'Transports communications et services publics'
    WHEN "F00_U_CODE" IS'3%' THEN "Utilisatio"  = 'Industrielle'
    WHEN "F00_U_CODE" IS'4%' THEN "Utilisatio"  = 'Transports, communications et services publics'
    WHEN "F00_U_CODE" IS'5%' THEN "Utilisatio" =  'Commerciale'
    WHEN "F00_U_CODE" IS'6%' THEN "Utilisatio"  = 'Services'
    WHEN "F00_U_CODE" IS'7%' THEN "Utilisatio"  = 'Culturelle, recreative et loisirs'
    WHEN "F00_U_CODE" IS'8%' THEN "Utilisatio"  = 'Production et extraction des richesses naturelles'
    WHEN "F00_U_CODE" IS'9%' THEN "Utilisatio" = 'Immeubles non exploites et etendues deau'
   END
  • 2
    You should probably use LIKE instead of IS. If "Utilisatio" is your new field, you don't have to specify it explicitely in the field calculator (just write WHEN "F00_U_CODE" LIKE '1%' THEN 'Residentiel' for instance). – ArMoraer Aug 7 '17 at 15:54
  • @ArMoraer - I think you should post your comment as an answer :) – Joseph Aug 8 '17 at 9:41
  • 1
    @Joseph: thanks for the suggestion, I don't always post a proper answer when to solution is so easy ;) – ArMoraer Aug 8 '17 at 9:52
  • @ArMoraer - What's easy for some might not be so easy for others ;) – Joseph Aug 8 '17 at 9:54
  • @ArMoraer Furthermore, answers are much more searchable than comments. – HDunn Aug 8 '17 at 10:33
2

You should probably use LIKE instead of IS.

If "Utilisatio" is your new field, you don't have to specify it explicitely in the field calculator (just write WHEN "F00_U_CODE" LIKE '1%' THEN 'Residentiel' for instance).

| improve this answer | |

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.