pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
adding fields containing NULL values
2+ messages / 2 participants
[nested] [flat]

* adding fields containing NULL values
@ 2000-05-29 11:58 Werner Modenbach <modenbach@alc.de>
  2000-05-29 13:43 ` Re: adding fields containing NULL values Grant Finnemore <gaf@ucs.co.za>
  0 siblings, 1 reply; 2+ messages in thread

From: Werner Modenbach @ 2000-05-29 11:58 UTC (permalink / raw)
  To: pgsql-sql

Hi all!

Let's say I have a table like:

employee  date        sallary   extras
--------------------------------------
Name1     01-31-1999  5000.00   NULL
Name1     02-29-1999  5000.00   500.00
Name1     03-31-1999  5000.00   NULL

I would like to get something like:

employee  date        total
-----------------------------
Name1     01-31-1999  5000.00
Name1     02-29-1999  5500.00
Name1     03-31-1999  5000.00

Umfortunately 'select employee,date,sallary+extras as total' doesn't give the
desired result because 'somevalue + NULL' is considered to be NULL. 
Is there any solution for my (small) problem?

- Werner -

BTW: I'm running PostgreSQL V 6.5.1

-- 
---------------------------------------
Werner Modenbach		 modenbach@alc.de
ALC Computertechnik GmbH	 http://www.alc.de



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: adding fields containing NULL values
  2000-05-29 11:58 adding fields containing NULL values Werner Modenbach <modenbach@alc.de>
@ 2000-05-29 13:43 ` Grant Finnemore <gaf@ucs.co.za>
  0 siblings, 0 replies; 2+ messages in thread

From: Grant Finnemore @ 2000-05-29 13:43 UTC (permalink / raw)
  To: pgsql-sql; +Cc: Werner Modenbach <modenbach@alc.de>

Werner,

> Umfortunately 'select employee,date,sallary+extras as total' doesn't give the
> desired result because 'somevalue + NULL' is considered to be NULL.
> Is there any solution for my (small) problem?

Try
    SELECT employee, date, salary + COALESCE(extras, 0) as total FROM ...

Regards

Grant

--
> Poorly planned software requires a genius to write it
> and a hero to use it.

Grant Finnemore BSc(Eng)  (mailto:gaf@ucs.co.za)
Software Engineer         Universal Computer Services
Tel  (+27)(11)712-1366    PO Box 31266 Braamfontein 2017, South Africa
Cell (+27)(82)604-5536    20th Floor, 209 Smit St., Braamfontein
Fax  (+27)(11)339-3421    Johannesburg, South Africa






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-05-29 13:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-05-29 11:58 adding fields containing NULL values Werner Modenbach <modenbach@alc.de>
2000-05-29 13:43 ` Grant Finnemore <gaf@ucs.co.za>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox