dbTalk Databases Forums  

needed: 1 + null = 1

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss needed: 1 + null = 1 in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Robert Klemme
 
Posts: n/a

Default Re: needed: 1 + null = 1 (Correction) - 05-31-2007 , 07:35 AM






On 31.05.2007 10:21, info (AT) vanoordt (DOT) nl wrote:
Quote:
Robert, it does make sense and the schema is build dynamically.
If you say so... To me this rather sounds like a case for

CREATE TABLE PARAMETERS (
item INT NOT NULL,
parameter_name VARCHAR(20) NOT NULL,
parameter_value INT NOT NULL,
PRIMARY KEY (
item,
parameter_name
)
)

Of course I don't know all the details...

Kind regards

robert


Reply With Quote
  #12  
Old   
Gert-Jan Strik
 
Posts: n/a

Default Re: needed: 1 + null = 1 (Correction) - 05-31-2007 , 01:11 PM






info (AT) vanoordt (DOT) nl wrote:
Quote:
I like Chris' last idea:
COALESCE(Col1, 0) + COALESCE(Col2, 0) + COALESCE(Col3, 0) +
0*COALESCE(Col1, Col2, Col3)

This calculates the value in one expression. I expect it to perform
well, at least not much worse than without the last term.

Gert-Jan, I need some time to find out what your code does. With all
respect, it lacks the simplicity of the above solution.
The code assumes that you did not properly normalize your table. It
assumes that Col1, Col2 and Col3 basically have the same meaning, and
should have been modelled as three rows. So the query is transposes the
three columns to three rows. Then the standard behavior of the SUM
aggregate is used, in which means NULLs are skipped. The result will
always be a scalar, and the SUM of an empty set is NULL.

Gert-Jan


Reply With Quote
  #13  
Old   
info@vanoordt.nl
 
Posts: n/a

Default Re: needed: 1 + null = 1 (Correction) - 06-01-2007 , 07:52 AM



Gert Jan, you have a point; sum() exactly does what is required.
Actually this is what I am investigating also, but it is a decision
with more implications.
Regards, Paul


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.