79522864

Date: 2025-03-20 12:08:16
Score: 3
Natty:
Report link

To set decimal precision dynamically in SQL Server, wrap the CAST within a ROUND. Set maximum needed decimals in CAST by hard coding, 16 in this example. Put the the @precision variable into ROUND.

 DECLARE @precison int
 select @precison = [ConfigValue] from [TestData] WHERE ConfigName = 'Precision'
 select ROUND(CAST( (10.56/10.25)as decimal(18, 16)), @precision)

Working example here (shows Stackoverflow User Rank and Top Percentage):

https://data.stackexchange.com/stackoverflow/query/1891785/stackoverflow-rank-and-percent-filtered-on-configurable-reputation-and-lastacce

Reasons:
  • Blacklisted phrase (1): Stackoverflow
  • Blacklisted phrase (1): stackoverflow
  • RegEx Blacklisted phrase (1.5): reputation
  • Probably link only (1):
  • Has code block (-0.5):
  • High reputation (-1):
Posted by: Emil Carpenter