473,839 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I show decimals after division update


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 51065
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!
Jul 20 '05 #11
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)
Jul 20 '05 #12
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!
Jul 20 '05 #13
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)
Jul 20 '05 #14
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!
Jul 20 '05 #15
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)
Jul 20 '05 #16

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

Similar topics

4
7957
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,
7
7712
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.
2
1627
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.
0
1224
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
5
2203
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...
5
2302
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...
12
2107
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...
5
2980
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://...
10
7137
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...
0
10584
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10645
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,...
0
10290
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 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...
0
9425
agi2029
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...
1
7827
isladogs
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...
0
5681
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...
0
5865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3131
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.