Click here to Skip to main content
15,885,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello

I have a table and on that table various fields are there some fields are null.

Suppose i want to fetch all the value like

select * from tablename

It fetch all the value.

I need that the value which are null it will replace to zero and i don't know which fields are null. I want to fetch query like : select * from tablename.



If any solution then please help.
Posted

Hi,

you can make use of ISNULL function of SQL. ISNULL function will replace the null value with the value you specify.
refer below article for more on ISNULL function.
ISNULL-MSDN[^]
SQL
--Example,
SELECT ISNULL(col1, 0), ISNULL(col2, 0), ISNULL(col3, ''), ISNULL(col4, GETDATE()) FROM TableName

also, i suggest, using "*" in select query is not good practice. specify the column names.

hope it helps.
 
Share this answer
 
Comments
Mohamed Mitwalli 21-Feb-13 0:16am    
5+
Karthik Harve 21-Feb-13 0:45am    
Thanks.!
Make use ISNULL keyword to make null columns return value as 0.
For ex:

SELECT ISNULL(column1,0) , ISNULL(column2,0) FROM TABLENAME

cheers. :)
 
Share this answer
 
Select Nvl(ColName,0) As ColNAme From TabName

ColName: Column Name, if it is Null then 0 will be displayed else its value will be displayed.

TabName: Table Name
 
Share this answer
 
Comments
MalwareTrojan 21-Feb-13 0:03am    
This is for PL/Sql or Oracle.
Hi,

U can use
SQL
ISNULL(), COALESCE()
Functions.

Check the following links

SQL NULL Functions[^]

Deciding between COALESCE and ISNULL in SQL Server[^]

ISNULL() VS. COALESCE()[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900