Thanks for your reply. In my case here, a customer was requesting a Purchase Order in pdf format, as well as Excel format. I was doing the rounding with a formula in Excel, but the formula did not always fill down to all the rows of the table which is why I decided to do the rounding in the query.
Also, quite often, in Winform apps, I pull a query into a DataTable, and set the DataTable as a DataGridView DataSource, in which case it seems more practical to do the rounding in the query as opposed to looping through the DataTable, and adding the rows with the rounded value to the DataGridView?
The problem is not a ROUND function, but the precision of the FLOAT data type (Using decimal, float, and real Data[^]). You have at least a couple of options:
1. Use DECIMAL or NUMERIC instead of the FLOAT.
2. CAST to DECIMAL for the calculation.
Here's the demonstration for you (using your first example): 1. Select using ROUND.
Tested below with the same random sample of 300 values, and all agreed with the Excel Values!
, price*qty as Val
, round(CONVERT(decimal(12,4),price)* CONVERT(decimal(12,4),qty),3) as RoundVal
What mis-lead me into thinking the problem was with the type of rounding was that from my sample of 300 values, all the values that differed had a 5 in the 4th decimal place, and all the errors were not rounded as expected.
In the link you poseted:
Using float and real Data
The float and real data types are known as approximate data types. The behavior of float and real follows the IEEE 754 specification on approximate numeric data types.
The IEEE 754 specification provides four rounding modes: round to nearest, round up, round down, and round to zero. Microsoft SQL Server uses round up. All are accurate to the guaranteed precision but can result in slightly different floating-point values. Because the binary representation of a floating-point number may use one of many legal rounding schemes, it is impossible to reliably quantify a floating-point value.
My Table has millions of records and my query is fetching 500 million records for 1 day to the SSRS report. so, It is taking too long time to fetch the data. Could anybody can suggest me how to narrow down or improve my query.
We have a relational DB in SQL Server 2008 which grinds up monthly data sets based on a set of criteria, these runs can take between 2 and 4 hours to produce and there may be 10-12 per month in 3-4 run sets. I am proposing that each run set has a cube for reporting and analysis.
The results are stored in 2 (fact) tables, each table has a view which pulls in the dimension fields, date, branch, product etc.
Each Run can result in +7m rows
Q1 Should I replicate the data into a reporting database before building the cube or build direct from the relational DB?
Q2 It has been recommended that I use the views, do I also need to pull in the dimension tables or can I use the fields in the view? eg Product dimension is serviced by a distinct of the Product column (answer - use the dimension table for cases where there is no record for a dimension element this period ).
Never underestimate the power of human stupidity
I am currently working on dash board application, I have a table say ‘User_data_master’
User_data_master(‘id’, ‘uid’, ‘data’, ‘instid’,’deptid’)
uid- user id referred to user bio data
data- data posted
deptid- department id
instid- institute id
Above table will store data for different employee from different department of an institution
In select query I need to get my rows belongs to me (I have saved), Then people from my department,
Then rest of rows which belongs to my Institute.
In my application there is a login and logout functionality.if i forget to logout and logout next day. i am unable to get the accurate difference between login and logout at backend..please can anyone help me
I have a database(Eg. SALES) in SQL Server 2014 which needs to be recreated in SQL Server 2012 version. Since I can not use the SQL 2014 back up file in SQL 2012 environment, I have proceed with the Generate Script option and trying to run the script in SQL Server 2012 environment. However it is giving an error as Msg 102, Level 15, State 6, Line 1
Incorrect syntax near 'DELAYED_DURABILITY'. which is pointing to the ALTER DATABASE [SALES] SET DELAYED_DURABILITY = DISABLED line in the script and not able to proceed further. Please help me to get this sorted out.