Quantcast
Channel: User Schwern - Stack Overflow
Viewing all articles
Browse latest Browse all 581

Answer by Schwern for Functions to filter missing values in SQL and change them to null values

$
0
0

You can use nullif which returns null if both values match, otherwise it returns the first value.

select  some_int,  nullif(some_int, 0),  some_text,  nullif(some_text, '0')from some_table

nullif is specific to your problem. More generically you'd use a case.

select  some_int,  case some_int    when 0 then null    else some_int  end as "case",  some_text,  case some_text    when '0' then null    else some_text  end as "case"from some_table;

Demonstration.


Viewing all articles
Browse latest Browse all 581

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>