How to replace NULL with 0 in SELECT Statement

Hi All

I have a query which gives results as

SELECT Id, number, number 2

FROM Table_123

ID

Number

Number 2

1

56

23

2

Null

Null

3

Null

Null

4

89

Null

 

How to write a query to replace all the Nulls with 0. The result should be like this

ID

Number

Number 2

1

56

23

2

0

0

3

0

0

4

89

0

December 12th, 2011 7:53pm

try this please

 

SELECT Id, isnull(number,0)number, isnull([number 2],0)[number 2]

FROM Table_123

 

VT

Free Windows Admin Tool Kit Click here and download it now
December 12th, 2011 7:56pm

Hello sir,

I am trying to replace 0 with some characters,but i couldn't do it .can you please answer to place a text like empty/nothing instead of 0 


You cant return empty string instead of 0 unless you change datatype to varchar. This would cause further issues if these values are used for further manipulations. So my suggestion should be to do these formatting at this front end if possible.
February 9th, 2015 7:56am

ram,

What is the data type of the column you are checking? 

Try

SELECT Id, isnull(value,'') from sometable

Free Windows Admin Tool Kit Click here and download it now
February 9th, 2015 7:59am

Thank you sir for your replay.

My data type of the column is INT. And I tried your line with small changes that casting then I got what I wanted.

Here my line of code is 

isnull(CAST(columnname as CHAR(4)),'Empty') as columnname_as_our_wish from tablename

February 10th, 2015 4:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics