You are here: Re: needed: 1 + null = 1 « MsSQL Server « IT news, forums, messages
Re: needed: 1 + null = 1

Posted by Chris.Cheney on 05/29/07 10:16

info@vanoordt.nl wrote in news:1180430739.196981.227870
@q69g2000hsb.googlegroups.com:

> Hi,
>
> I need this behaviour: 1 + null = 1
> I have a (dynamic) set of many columns containing decimals that I want
> to add as follows:
> if all columns are null the result should be null
> if not all columns are null, the null columns may be regarded as 0.
>
> E.g.
> null + null + 1 = 1
> null + null + null = null
>
> The problem is that the first expression yields null.
>
> Up till now I generated an update statement with isnull(<column>,0),
> however, then the second expression yields 0.
> I can add another update statment setting the result to null if all
> columns are null, but this is very slow, and not very intuitive
> either.
> How nice it would be if there were a setting like 'concat null yields
> null' for arithmetic operators.
>
> Anyone any idea how to fix this?
>
> Thanks.
> Paul
>
>

COALESCE(Col1, 0) + COALESCE(Col2, 0) + COALESCE(Col3, 0) + COALESCE(Col1,
Col2, Col3)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация