Prabhu
Prabhu

Reputation: 13335

variable decimal places in sql

How do you make it so that all calculations in the DB compute to a pre-specified # of decimal places? Say I have three tables with the following fields

Table1

Table2

Table3

Now I need to change it so that all my calculations are based on what precision is set for A in Table3. I started by converting all my decimals to decimal (30, 10) to allow for higher precisions if specified.

Upvotes: 0

Views: 4254

Answers (2)

Bernard
Bernard

Reputation: 7961

Try using the ROUND function in a stored procedure that first retrieves the precision from your Table3 table.

Upvotes: 1

JNK
JNK

Reputation: 65167

Wrap your results in a CAST statement to set them to the desired precision. I.e.:

SELECT CAST((<query>) AS int) AS Result

Upvotes: 3

Related Questions