Beast Mode to null out values

Options

Why is this SQL code throwing an error associated with the NULL?

CASE
WHEN `hire_year` = ‘2022’ THEN `percent_value`
WHEN `hire_year` != ‘2022’ THEN NULL
END

Best Answers

  • ColemenWilson
    Answer ✓
    Options

    Is there a particular reason you need them to be null? If they are numeric values you can set them to = 0 and if they are strings you can set them to = ‘’

    it looks like you are working with percentages, so could you just set it to = 0?

    If I solved your problem, please select "yes" above

  • MarkSnodgrass
    Answer ✓
    Options

    Is 2022 a column? Or is it a string value? You have the ` around both sides of it which is used for columns names. If 2022 is not a column, it will throw an error. If you are wanting to look for the string value 2022 then you should have single quotes around it.

    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.

Answers

  • Just use THEN ‘’ END

    If I solved your problem, please select "yes" above

  • bcook
    Options

    That solution is still throwing an error.

  • Hmm maybe just eliminate line 3 and replace it with ELSE ‘’

    If I solved your problem, please select "yes" above

  • bcook
    Options

    Is there a way to just set it to NULL?

  • ColemenWilson
    Answer ✓
    Options

    Is there a particular reason you need them to be null? If they are numeric values you can set them to = 0 and if they are strings you can set them to = ‘’

    it looks like you are working with percentages, so could you just set it to = 0?

    If I solved your problem, please select "yes" above

  • MarkSnodgrass
    Answer ✓
    Options

    Is 2022 a column? Or is it a string value? You have the ` around both sides of it which is used for columns names. If 2022 is not a column, it will throw an error. If you are wanting to look for the string value 2022 then you should have single quotes around it.

    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • Good catch @MarkSnodgrass, I was looking at it on my phone and the ticks appeared to be ' not `

    If I solved your problem, please select "yes" above