Solved

SQL 2000: Change all values of a column to 0 where the value is currently NULL

Posted on 2007-03-23
4
2,448 Views
Last Modified: 2008-04-09
I have a table entitled insurance_details_tbl that contains several float columns - I woult like to change all values in each column that are NULL to 0.

I have the below query (doing it column by column currently), which executes without error but changes nothing:

UPDATE    insurance_details_tbl
SET              value_computer = 0
WHERE     (value_computer = 'NULL')
0
Comment
Question by:wbstech
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 18778982
try it with out the ' around null (this makes it a string comparison)

UPDATE    insurance_details_tbl
SET              value_computer = 0
WHERE     (value_computer = NULL)
0
 
LVL 4

Author Comment

by:wbstech
ID: 18778984
Ah - copied and pasted the wrong one. Already tried that - same result.
0
 
LVL 15

Accepted Solution

by:
Colosseo earned 250 total points
ID: 18779000
try

UPDATE    insurance_details_tbl
SET              value_computer = 0
WHERE     (value_computer IS NULL)

Scott
0
 
LVL 11

Expert Comment

by:Sven
ID: 18779341
Or for more than one column in one statement:

UPDATE table
SET column1 = isnull(column1,0), column2 = isnull(column2,0)

Beware that this UPDATE will update ALL rows indenent if there a NULL values in the columns or not. But only NULL values will change to 0, all other values are updated with theire own value.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now