Solved

How can i replace NULL with 0.00 in TSQL

Posted on 2002-04-09
6
2,568 Views
Last Modified: 2008-02-01
How can i write a select statment which display 0.00 for each Null value
I have a query as follows.

Select field1, field2 from table1

output
-------
1     2.25
2     1.50
3     Null
4     12.00


output should be
---------------
1     2.25
2     1.50
3     0.00
4     12.00
0
Comment
Question by:bcp5190
6 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 6928463
You can do this:

Select field1, ISNULL(field2,0.00)
FROM table1

0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 6928491
Unfortunately, I don't know of any way to specify a global replacement value for NULL, like, for example, the SET NULL 'value' option in Oracle.
0
 
LVL 1

Expert Comment

by:Brighton
ID: 6929281
You could also set the default value for field2 to 0 when you created the table with

CREATE TABLE TABLE1 ( field1 NUMERIC(18,2),
field2 NUMERIC(18,2) DEFAULT 0)
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 20 total points
ID: 6929473
The only problem with using a default of zero to (try to) replace NULL is that you sometimes can't tell the difference between data this is zero and is unknown.

I realize that in your situation you may not have an issue with that, but just try to think through the possibilties carefully before you're sure of that.

For example, I once worked at a place that defaulted an item's price to zero if they hadn't determined its price yet ("after all, we'll don't give any items away").  Well, later they did start allowing customers to order literature (sales brochues, etc.) free as part of an order.  It was a LOT OF WORK to correct the system to allow zero prices and still be able to identity unknown prices.

I admit that there is some additional programming required to handle nulls and that programmers generally don't like them, but if they may be needed to maintain accurate data, I say use them.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6930563
Another function that ISNULL is COALESCE, with the only difference that it could accept more than 2 arguments...

CHeers
0
 

Author Comment

by:bcp5190
ID: 6931166
Thanks ScottPletcher.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

863 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

23 Experts available now in Live!

Get 1:1 Help Now