way to have query with case statement

Viewed 21

I have table called Numbers in that column I have values from 0 - 10 but I like to keep value of 1-10 only change record of 0 too null

Case numbers when 0 then ''

but I found this has changed all values and not values that have 0 is there way I can say else leave value as is?

2 Answers

Do you want this?

update t
    set number = null
    where number = 0;

Or as a select:

select t.*,
       (case when number <> 0 then number end)
from t;
SELECT CASE WHEN [column] = 0 THEN NULL ELSE [column] END AS [SomeName]
FROM Numbers
Related