October 30, 2010 at 3:55 am
I have one table with a few columns that may be NULL, like this:
COL1 COL2 COL3
1 AA NULL
2 BB 29
3 AA 10
4 AB NULL
5 BB 15
I would like to get a result with all columns from that table, but replacing all NULL values with 0, like this:
COL1 COL2 COL3
1 AA 0
2 BB 29
3 AA 10
4 AB 0
5 BB 15
I know I can do
select col1, col2, isnull(col3, 0)
from mytable
but I do not want to name all the columns in my select... I would like a statement where I can say "return all columns, but for the rows where COL3is NULL, return 0".
If I do
select *, isnull(col3, 0)
from mytable
my result set is
COL1 COL2 COL3 (no column name)
1 AA NULL 0
2 BB 29 29
3 AA 10 10
4 AB NULL 0
5 BB 15 15
Instead of replacing COL3, I get an extra column showing non-NULL values!
Is there any way of getting a result set where COL3 will show 0 instead of NULL?
October 30, 2010 at 5:34 am
I think you will have to list the columns...
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply