dbTalk Databases Forums  

SUM(NULL) not work

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss SUM(NULL) not work in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Rob Waywell
 
Posts: n/a

Default Re: SUM(NULL) not work - 11-22-2007 , 10:44 AM






To be clear the following script will return the sum of 6 in both ASA 8.x
and SQL Anywhere 10.x:

create table t1
( row_id int default autoincrement primary key,
row_int int,
row_char char(30)
);

insert into t1(row_int) values (1);
insert into t1(row_int) values (NULL);
insert into t1(row_int) values (2);
insert into t1(row_int) values (3);
commit;

select sum(row_int) from t1;

As Chris has pointed out the only difference is that in version 10.x we
*properly* report the *warning* - a positive SQL Code value - that a NULL
value was eliminated or ignored in computing that sum. The recommended way
to handle this is to explicitly handle the *warning* in the application.
However, we know that some development tools do not allow the application to
handle the warning but arbitrarily treat it as an error. For those
development environments we have provided the option to "Suppress Fetch
Warnings" in the ODBC configuration. Note that this is *different* from the
"Delphi Applications" option.

Can you confirm that you have explicitly checked the "Suppress Fetch
Warnings" option and that you are still receiving the warning SQLCode = 109?

--
-----------------------------------------------
Robert Waywell
Sybase Adaptive Server Anywhere Developer - Version 8
Sybase Certified Professional

Sybase's iAnywhere Solutions

Please respond ONLY to newsgroup

EBF's and Patches: http://downloads.sybase.com
choose SQL Anywhere Studio >> change 'time frame' to all

To Submit Bug Reports:
http://case-express.sybase.com/cx/cx...c?CASETYPE=Bug

SQL Anywhere Studio Supported Platforms and Support Status
http://my.sybase.com/detail?id=1002288

"Fantom" <szczukot (AT) poczta (DOT) onet.pl.skasujto> wrote

Quote:
You're right. I should have read better.

You wrote: Why this NULL <> 0?

Null means the fields is undefined and has no value. '0' mean it has a
value of '0'.

You could add default values to the fields in the database for the fields
having this problem. That will also solve it.

But in ASA8 when i sum (1+null+2+3) i get 6.
When i convert database to 10 i have big problem, because my aplication is
hung up when in SUM exists NULL.

Fantom

Frank

Fantom wrote:
Why not use SUM(IsNull(Data,0)) that solves all the problems and
warnings.


I write in first post : i have thousends statement of this type.

Fantom


Frank

Fantom wrote:

SQLCODE 109 is merely a warning, not an error. The warning indicates
that at least one NULL value of column "data" was read from the table
and ignored in the computation of SUM.

This warning was also present in ASA 8 servers, but the ODBC interface


I use ODBC and aplication hang up when this type of statement is
runing.



would fail to pass that warning back to the application properly. That
issue was fixed in a subsequent release.


Now i use the newest 10.0.1.3579 and aplication not work ok (borland
with ODBC and BDE) - no response and i must close aplication. In Sybase
Central 10 i get warning on this statement.
When i run aplication on 8.0.3 this aplication work properly.

Fantom



Glenn

Fantom wrote:


Hi
when i want set SUM(data) and data sometimes is NULL and this
statement return error (sqlcode = 109). Why this NULL <> 0 ?
In ASA8 this is work. Now i tested this on ASA 10.0.1.

Fantom
ps. SUM(ISNULL(data, 0)) is work OK, but i don't want change all
statements with agregate function in my aplication.

--
Glenn Paulley
Director, Engineering (Query Processing)
iAnywhere Solutions Engineering

EBF's and Patches: http://downloads.sybase.com
choose SQL Anywhere Studio >> change 'time frame' to all

To Submit Bug Reports: http://case-express.sybase.com

SQL Anywhere Studio Supported Platforms and Support Status
http://my.sybase.com/detail?id=1002288

Whitepapers, TechDocs, and bug fixes are all available through the
iAnywhere
Developer Community at www.ianywhere.com/developer








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.