change null to 0 in SQL script

Поиск
Список
Период
Сортировка
Искать

change null to 0 in SQL script

От:
"Karl Raven" <lcaasia@pd.jaring.my>
Дата:

I like to change a null value of a query to 0 in the SQL script. I know how
to do it in MS-SQL server and MS-Access but those commands does not work in
pg-sql.

Anyone has any ideas?

Thanks




Re: change null to 0 in SQL script

От:
Markus Bertheau <twanger@bluetwanger.de>
Дата:
On Thu, 2002-01-03 at 06:00, Karl Raven wrote:
> 
> I like to change a null value of a query to 0 in the SQL script. I know how
> to do it in MS-SQL server and MS-Access but those commands does not work in
> pg-sql.
> 
> Anyone has any ideas?

What did you try?

Markus Bertheau

Re: change null to 0 in SQL script

От:
"Tibor Laszlo" <ltibor@mail.tiszanet.hu>
Дата:
> I like to change a null value of a query to 0

The coalesce(something, 0) returns 0 if something is null, else returns
something.


Tibor Laszlo
ltibor@mail.tiszanet.hu


Re: change null to 0 in SQL script

От:
Jason Earl <jason.earl@simplot.com>
Дата:

I believe that you need the coalesce function.  Here's the excerpt
from the manual:
       COALESCE
       COALESCE(value[, ...])
       The COALESCE function returns the first of its arguments that       is not NULL. This is often useful to substitute a default       value for NULL values when data is retrieved for display, for       example:
       SELECT COALESCE(description, short_description, '(none)') ...


Just write your query so that it looks something like this:

SELECT coalesce(value_that_may_be_null, 0) FROM your_table;

Jason


"Karl Raven"  writes:

> I like to change a null value of a query to 0 in the SQL script. I
> know how to do it in MS-SQL server and MS-Access but those commands
> does not work in pg-sql.
> 
> Anyone has any ideas?
> 
> Thanks
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: change null to 0 in SQL script

От:
ThomasR <trx@wtal.de>
Дата:
Karl Raven wrote:

> I like to change a null value of a query to 0 in the SQL script. I know how
> to do it in MS-SQL server and MS-Access but those commands does not work in
> pg-sql.
> 
> Anyone has any ideas?
> 
> Thanks
> 

I think the following should work:

select coalesce( my_attrib, 0 ) from my_tab

Thomas


Re: change null to 0 in SQL script

От:
"Karl Raven" <lcaasia@pd.jaring.my>
Дата:
thanks
will try it..


"ThomasR"  wrote in message news:3C360816.1080103@wtal.de...
> Karl Raven wrote:
>
> > I like to change a null value of a query to 0 in the SQL script. I know
how
> > to do it in MS-SQL server and MS-Access but those commands does not work
in
> > pg-sql.
> >
> > Anyone has any ideas?
> >
> > Thanks
> >
>
> I think the following should work:
>
> select coalesce( my_attrib, 0 ) from my_tab
>
> Thomas
>



FAQ