Encountered in the work, a multi-table joint query, the query out some of the field precision is too high, the decimal point to reach 8 0, now customers require the report as long as accurate to 0.01, as long as only after the decimal point to save two bits, also need to round
On the Internet to find some information, their own test, the following for everyone to share the following:
---Create a test table
Use Testcreate TABLE studentscore (id INT IDENTITY (PRIMARY) KEY, score VARCHAR (20)) The following is the insertion of these data
1. Do not change the values in the table, only when the query is displayed, rounding only two decimal places reserved
Select Convert (Decimal (18,2), score) from Studentscore execution Result:
2. Directly update the values in the table, rounding only two decimal places
Update Studentscore Set score = cast (CAST (round (score,2) as float) as varchar) where CHARINDEX ('. ', REVERSE (cast (score as V Archar ())) -1>3 The updated database:
Precision issues with fields in SQL Server