|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
Still get rounded results with that
I take it this is quite unusual? |
|
#6
|
|||
|
|||
|
ya pretty weird, maybe those fields have a defined length when you created the table? Hopefully someone sees this soon.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Rounding problem in Sum() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|