I have a table defined as follows:
create table
(bar float)
And I'm looking for a way to round every value contained in a column without changing the total amount (which, as you know, is an integer or very close to an integer due to the precision of the floating point number).
Rounding each value to the nearest integer will not work (for example: 1.5; 1.5 will be rounded to 1; 1 or 2; 2)
This is quite easy to do using a few queries (for example, storing the original amount, rounding, calculating the new amount and updating as many lines as necessary to return to the original amount), but this is not a very elegant solution.
Is there a way to do this using a single SQL query?
I am using SQL Server 2008, so welcome solutions using this particular provider.
Edit: I'm looking for a query that minimizes the differences between old values and new ones. In other words, the value should never be rounded if the larger value is rounded down and vice versa
Brann source
share