Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Convert nulls to zero with SQL

kvrensanchez
6 - Meteoroid

Hello,

 

I am pulling data through an ODBC, and am returning nulls with the below statement. How can I edit this SQL code so that if it returns a null, it converts it into a zero? I know I can use data cleansing, but it may slow down my process and wanted to have it written in the SQL code.

 

Sum(P.COGSAmount) as CostOfGoodsSold,

 

Thank you!

 

 

4 REPLIES 4
Raj_Singh1
9 - Comet

probably some thing around 

 

 

 

if x is null then 0 else y

Raj_Singh1
9 - Comet

hi @kvrensanchez 

i sually use syntax something like this with case staement

 

 

case when field is null then 0 else field end as 'new_field)

 

 

so if you writing 

 

select field1, field2, case when field1 is null then 0 else field end as 'new_field_name'  from xyz where etc etc

kelsey_kincaid
12 - Quasar

Hi @kvrensanchez ,

 

You can use a COALESCE statement to set Nulls to Zero.

 

COALESCE(SUM(P.COGSAmount), 0) as CostOfGoodsSold,
kvrensanchez
6 - Meteoroid

Thank you! This was it.

Labels