Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
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 20-Feb-13 18:43pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
--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.
  Permalink  
Comments
Mohamed Mitwalli at 21-Feb-13 0:16am
   
5+
Karthik Harve at 21-Feb-13 0:45am
   
Thanks.!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Make use ISNULL keyword to make null columns return value as 0.
For ex:
 
SELECT ISNULL(column1,0) , ISNULL(column2,0) FROM TABLENAME
 
cheers. Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Comments
Vardhan Desai at 21-Feb-13 0:03am
   
This is for PL/Sql or Oracle.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
 
U can use
 ISNULL(), COALESCE()
Functions.
 
Check the following links
 
SQL NULL Functions[^]
 
Deciding between COALESCE and ISNULL in SQL Server[^]
 
ISNULL() VS. COALESCE()[^]
  Permalink  

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

  Print Answers RSS
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100