Skip to content
Advertisement

How to turn a number to zero if the result of a calculation is negative inside a squareroot in BigQuery?

I have a query that can result in a negative squareroot, leading to an error. I’m using BigQuery. Is there a way to turn the result in to a 0 if inside de POWER() function is less than 0?

Here’s my query:

The negative squareroot can happen here:

So, if the result of

is less than zero, I would like to set it to zero instead.

Is it possible to do this?

Thanks in advance!

Advertisement

Answer

You can use GREATEST():

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement