I have a table which I want to update by dividing one field into
another. The update runs with no errors, but the results come out as
only a positive integer number.
The datatype for the result field is float.
The datatype for the other fields are int.
I have tried testing by dividing 7 by 10000, which should give me
0.0007. The result in the database is 0.
How do I define a field to show the full value with decimal positions?
If I enter .0007 into the field through the Enterprise Manager, it shows
0007. When I update by dividing, it shows 0.
Any help would be welcome.
Joel
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05
15 51057
Hugo,
I started to list the columns in the table with their datatypes and as I
was doing this I realized that the datatypes for the fields I am
dividing are "int".
I changed them to decimal and it solved the problem.
If I hadn't gone through the exercise of listing the columns and their
datatypes I might have taken a lot longer to realize the problem.
I never had this problem with Access, which is why I did not recognize
the solution.
Thanks,
Joel
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
On 22 Apr 2004 13:57:12 GMT, joel wrote: Hugo,
I started to list the columns in the table with their datatypes and as I was doing this I realized that the datatypes for the fields I am dividing are "int".
I changed them to decimal and it solved the problem.
If I hadn't gone through the exercise of listing the columns and their datatypes I might have taken a lot longer to realize the problem.
I never had this problem with Access, which is why I did not recognize the solution.
Thanks,
Joel
Hi Joel,
You don't need to change the datatype just to get the division
correct. If the columns themselves contain integer data, change them
back to int.
The division will also work correctly if you write
UPDATE ....
SET FloatCol = CAST(IntCol1 AS float) / IntCol2
WHERE ....
SQL Server will switch to non-integer division as soon as one of the
operands in of a float or decimal type. The cast explicitly converts
the IntCol1 to float before the division is carried out. Without the
cast, the division would have been made first (as integer division,
thus losing all fractions) and converted to float afterwards (to store
the result in FloatCol).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Hugo,
I have been reading this thread and I am running into a similar problem.
I am using the CAST but I am still getting a return of 0.0 any help
would be greatly appreciated. Here is my code:
select cast(count(Safe tyTrainingYN) AS FLOAT)
from ICPCDATA
where SafetyTrainingY N = 1 /
(select count(SafetyTra iningYN)YES
from ICPCDATA)
remove _nospam_ for my email
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
On 29 Apr 2004 17:57:18 GMT, Josh Phillips wrote: Hugo,
I have been reading this thread and I am running into a similar problem. I am using the CAST but I am still getting a return of 0.0 any help would be greatly appreciated. Here is my code:
select cast(count(Safe tyTrainingYN) AS FLOAT) from ICPCDATA where SafetyTrainingY N = 1 / (select count(SafetyTra iningYN)YES from ICPCDATA)
remove _nospam_ for my email
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi Josh,
I can't test right now, but it looks like a parethesis problem.
(I assume the extra "YES" is a typo? Otherwise, this should give you a
syntax error!)
The server will count the number of non-NULL values in
SafetyTrainingY N in ICPCDATA. It will then calculate 1 / that number,
as integer division (yielding 0). Next, it will find rows in ICPCDATA
with SAfetyTrainingY N = that result (0). Apparently, there are none,
so the count(..) yields 0. This is converted to float and the result
is given to you: 0.0
What you probably meant is:
select (select cast(count(Safe tyTrainingYN) AS FLOAT)
from ICPCDATA
where SafetyTrainingY N = 1) /
(select count(SafetyTra iningYN)
from ICPCDATA)
By the way, why don't you use 'Y' and 'N' instead of 1 and (I think) 2
to represent yes and no? You even have Y and N in the columns' name!
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Hugo,
I have been reading this thread and I am running into a similar problem.
I am using the CAST but I am still getting a return of 0.0 any help
would be greatly appreciated. Here is my code:
select cast(count(Safe tyTrainingYN) AS FLOAT)
from ICPCDATA
where SafetyTrainingY N = 1 /
(select count(SafetyTra iningYN)YES
from ICPCDATA)
remove _nospam_ for my email
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
On 29 Apr 2004 17:57:18 GMT, Josh Phillips wrote: Hugo,
I have been reading this thread and I am running into a similar problem. I am using the CAST but I am still getting a return of 0.0 any help would be greatly appreciated. Here is my code:
select cast(count(Safe tyTrainingYN) AS FLOAT) from ICPCDATA where SafetyTrainingY N = 1 / (select count(SafetyTra iningYN)YES from ICPCDATA)
remove _nospam_ for my email
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi Josh,
I can't test right now, but it looks like a parethesis problem.
(I assume the extra "YES" is a typo? Otherwise, this should give you a
syntax error!)
The server will count the number of non-NULL values in
SafetyTrainingY N in ICPCDATA. It will then calculate 1 / that number,
as integer division (yielding 0). Next, it will find rows in ICPCDATA
with SAfetyTrainingY N = that result (0). Apparently, there are none,
so the count(..) yields 0. This is converted to float and the result
is given to you: 0.0
What you probably meant is:
select (select cast(count(Safe tyTrainingYN) AS FLOAT)
from ICPCDATA
where SafetyTrainingY N = 1) /
(select count(SafetyTra iningYN)
from ICPCDATA)
By the way, why don't you use 'Y' and 'N' instead of 1 and (I think) 2
to represent yes and no? You even have Y and N in the columns' name!
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bill |
last post by:
I have some values that I want to display as percent, such as the
retail price/wholesale price. In some instances, the wholesale price
is zero, so I get a division by zero error.
What can I do to avoid this?
Also, how can I get this to only show two decimals, instead of it
going .##### the way it does. I want it to look like .45%
Thanks a million,
|
by: joel |
last post by:
I have a table which I want to update by dividing one field into
another. The update runs with no errors, but the results come out as
only a positive integer number.
The datatype for the result field is float.
The datatype for the other fields are int.
I have tried testing by dividing 7 by 10000, which should give me
0.0007. The result in the database is 0.
|
by: MLH |
last post by:
An attached table named tblCustomers (but without the capital C)
is attached to my Access database. The table is a remote MySQL
table. I can read it and even make some changes to its data
manually in table view.
I would like an example PassThrough query's SQL to show how
to update . to True. Thanks.
|
by: FST |
last post by:
Hello All,
Why does the database update from inside the Button1_Click event, but won't
update from inside the DataGrid1_CurrentCellChanged event when I change
cells? The message from inside the DataGrid1_CurrentCellChanged event
appears but OleDbDataAdapter1.Update(DataSet11) doesn't happen.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
|
by: cover |
last post by:
I have an input form that passes data when submitted to a second form
to let the user know what they have just entered into the db.
My question comes with using 'update'. I'd like to query the database
by equipment number (equipno is unique) and query all fields from that
row, populating an original form 'look alike' whereby the user can add
detail to the original records as the db builds. I'm using 'date'
twice because I'd like to...
| |
by: heddy |
last post by:
I have a listbox that gets populated in code by a reader result set
from a stored proc on SQL Server 2005. In building this I created a
set of test rows in the DB and the code runs fine and populates the
box. Next I added functionality to add data. This adds data to the DB
and then forces the listbox to refresh by clearing it's contents and
then re-running the populate code.
However, when I add an item and do the refresh, the listbox...
|
by: CNiall |
last post by:
I am very new to Python (I started learning it just yesterday), but I
have encountered a problem.
I want to make a simple script that calculates the n-th root of a given
number (e.g. 4th root of 625--obviously five, but it's just an example
:P), and because there is no nth-root function in Python I will do this
with something like x**(1/n).
However, with some, but not all, decimals, they do not seem to 'equal
themselves'. This is...
|
by: question.boy |
last post by:
I am trying to control the visibility of a set of div based on
selected values but can't seem to get it right. Below is what I have
so far but it does not work at all.
The basic concept was to have a set of Divs A through Z and by click
the associated text character that Div would be visible and all others
would be hidden.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://...
|
by: truptivk |
last post by:
Hello all,
I have a situation and I'd appreciate it if any of you could help me. I am not sure if this is js or html but here goes. I have a main combo box (mcb) which I'm displaying some values.
Based on what the user chooses, 2 combo boxes should be displayed on same page. The first combo box (CB1), should be filled with some values. The second, (CB2) however, should get loaded on basis of what is chosen in CB1. UNtil then, CB2 should be...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |