MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 5th, 2004, 05:58 PM
PFunk PFunk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 PFunk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Rounding problem in Sum()

I am having issues with a query where I sum the product of two cells - one is a float and one is an int. For some reason the float column is rounded to an int meaning that the results are very inaccurate.

What am I doing wrong?

Reply With Quote
  #2  
Old May 5th, 2004, 11:46 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
right, seen this b4. Are you using SQL Server? Can you post the Select statement? I'm thinking you may have to cast the int to a float.

Reply With Quote
  #3  
Old May 6th, 2004, 04:36 PM
PFunk PFunk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 PFunk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've tried casting to a Float and all that happens is I get the rounded number with a .0 on the end ??

SQL below:

Code:
SELECT
	Sum(Cast(ProductQuantity AS Float)*Cast(ProductDisplayPrice AS Float)), Branch.BranchID,BranchName
FROM
	Branch
INNER JOIN
	Users
ON
	Users.BranchID = Branch.BranchID
INNER JOIN
	ProductOrder
ON
	ProductOrder.UserID = Users.UserID
INNER JOIN
	OrderItem
ON
	OrderItem.OrderID = ProductOrder.OrderID
WHERE
	Users.ProgrammeID = 'PlaceMk'
GROUP BY Branch.BranchID,BranchName

Reply With Quote
  #4  
Old May 6th, 2004, 08:15 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
gees, not sure to tell you the truth. I've been testing this and I can easily sum or multiply 2 numbers of diff data types. Sorry, someone else hopefully has your solution.

If you can, take out the sum and the casting, just multiply the 2 fields...
Code:
select  ProductQuantity * ProductDisplayPrice 
from    Branch
...

...what do you get then?

Reply With Quote
  #5  
Old May 6th, 2004, 08:58 PM
PFunk PFunk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 PFunk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Still get rounded results with that

I take it this is quite unusual?

Reply With Quote
  #6  
Old May 7th, 2004, 12:18 AM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
ya pretty weird, maybe those fields have a defined length when you created the table? Hopefully someone sees this soon.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Rounding problem in Sum()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway