473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: SQL - Unexpected result

I give you a hint:
db2 =values 1/2;

1
-----------
0

1 record(s) selected.

db2 =values 1.0/2;

1
------------------------------------------
0.5

1 record(s) selected.

Let the slapping begin.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #1
5 1626
On Mon, 19 May 2008 11:21:57 -0400, Serge Rielau <sr*****@ca.ibm.com>
wrote:
>I give you a hint:
db2 =values 1/2;

1
-----------
0

1 record(s) selected.

db2 =values 1.0/2;

1
------------------------------------------
0.5

1 record(s) selected.

Let the slapping begin.
Serge,

Thanks for the quick reply. :)

I see in the documentation that if either operand of an arithmetic
operator is floating point, the operation is performed in floating
point. I assume that is what I am seeing here, right? So how would I
solve my problem? I need to be able to calculate a float value from
two integer values.

I apologize for these basic questions, but I am relatively new to DB2,
and some of the things I have taken for granted with other RDBs (like
the above problem) are not so simple with DB2.

Jm

Jun 27 '08 #2
Allthough, you didn't give any DDL, my first impression was(maybe same
as Serge) that all CFYARDS, PMCOST3, PMCOST4, PMCOST2, CRCOST1,
PMCOST6, CFYARDS, and ODPR*ICEY might be integer and intermittent
results were integer, then lost decimal part.
If this guess was right, follwings might give you the answer.
CAST(Sum(CFYARDS)*(PMCOST3+PMCOST4+PMCOST2+CRCOST1 +PMCOST6) AS
DEC(11,0))/(Sum(CFYARDS)*ODPR*ICEY)*100
(it may be neccesary to change 11 and 0 for DEC(p,s).)
or
(Sum(CFYARDS)*(PMCOST3+PMCOST4+PMCOST2+CRCOST1+PMC OST6)*100.)/
(Sum(CFYARDS)*ODPR*ICEY)
Jun 27 '08 #3
jmoseby_@_elasticfabrics.com wrote:
On Mon, 19 May 2008 11:21:57 -0400, Serge Rielau <sr*****@ca.ibm.com>
wrote:
I give you a hint:
db2 =values 1/2;

1
-----------
0

1 record(s) selected.

db2 =values 1.0/2;

1
------------------------------------------
0.5

1 record(s) selected.

Let the slapping begin.
Serge,

Thanks for the quick reply. :)

I see in the documentation that if either operand of an arithmetic
operator is floating point, the operation is performed in floating
point. I assume that is what I am seeing here, right? So how would I
solve my problem? I need to be able to calculate a float value from
two integer values.

I apologize for these basic questions, but I am relatively new to DB2,
and some of the things I have taken for granted with other RDBs (like
the above problem) are not so simple with DB2.
If you need a float value: DOUBLE(COL6)/COL9*100 would do it (FLOAT is
a synonym for DOUBLE if you want). If an integer percentage is
sufficient (COL6*100)/COL9 would be fine (assuming COL6 doesn't get so
large that multiplying by 100 would overflow a 32-bit signed integer).
Cheers,

Dave.
Jun 27 '08 #4
Plese try:
CAST(Sum(CFYARDS)*(PMCOST3+PMCOST4+PMCOST2+CRCOST1 +PMCOST6) AS
DEC(11,0))/(Sum(CFYARDS)*ODPR*ICEY)*100
(it may be neccesary to change 11 and 0 for DEC(p,s).)
or
(Sum(CFYARDS)*(PMCOST3+PMCOST4+PMCOST2+CRCOST1+PMC OST6)*100.)/
(Sum(CFYARDS)*ODPR*ICEY)

Jun 27 '08 #5
jmoseby_@_elasticfabrics.com wrote:
I apologize for these basic questions, but I am relatively new to DB2,
and some of the things I have taken for granted with other RDBs (like
the above problem) are not so simple with DB2.
Hmm.. you use plural: rdbS. The only RDB where I'd expect to see a
difference is Oracle. But then in Oracle your column wasn't defined as
INTEGER. It was defined as NUMBER which is - not integer :-)
(If you specify INTEGER in Oracle you don't get INTEGER btw. You still
get NUMBER)

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
62
by: ashu | last post by:
hi look at this code include <stdio.h> int main(void) { int i,j=2; i=j++ * ++j * j++; printf("%d %d",i,j); return 0;
5
by: devereaux | last post by:
I'm trying to run a script and it's throwing the following error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR in openfile.php on line 41 Here is the openfile.php file and I have...
13
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
2
by: =?Utf-8?B?QXJtaW4gR2FsbGlrZXI=?= | last post by:
Hi I've got an unexpected error in a unit test. I want to test a activity from Windows Workflow Foundation (WF). First, I executed the test outside of the activity just in the test-init...
11
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition:...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
14
by: Padfoot153 | last post by:
Hey, I'm getting the error: Parse error: syntax error, unexpected T_VARIABLE in /Users/Oscar/AwesomeSongz/userCake/profile.php on line 7 with this code <?php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.