开发者

Perform Mathematical operations in T-SQL or at Runtime

开发者 https://www.devze.com 2023-02-16 14:47 出处:网络
I am currently working on a report where the results of this report are being generated inside of a stored procedure.

I am currently working on a report where the results of this report are being generated inside of a stored procedure.

For this report I am returning a list of records that contain a numerator and denominator respectively. When the report is display the actual percentage result (Numerator/Denominator) will need to be displayed al开发者_如何学编程ong side these numbers.

The question becomes is it a great performance gain to generate these percentages inside of the stored procedure and have them return the calculated percentage or to just return the two numbers and have the runtime environment for the report generate the percentage?

The runtime environment for the report will vary, it will primarily be a page inside of a Silverlight application passed through a WCF web service. Alternatively there will be a rdlc report viewer option available as well so they can view the report directly through the browser.


Hard to answer this one - broadly speaking, I'd guess it isn't something you'd worry about - milli-seconds either way.

However, for sanity reasons, I'd do it on the server. If the calculation has any kind of business impact, you want it to be consistent whichever system runs the report.

Oh, and test for rounding - different applications round differently, often in unexpected ways...


If you don't need to perform a query on the result and if it's not a complex calculation, then I'd let the client calculate the percentage for 2 reasons.

1- It will reduce the amount of data that goes on the wire.

2- If your server has to handle a lot of queries per seconds, it will reduce it's payload.

However, in both case, you will notice change only when large amount of data are involved.


If you're thinking as an architecture like MVVM, you'd want to avoid doing this in a proc and only return values that are related to your model. You'd then extend your model to contain the calculated field.

If you're looking for the 'get-r-done' method then just calculate it in the query. Since you're sending the two values anyway, there's no added cost there (not that there would be anyway). A simple divide won't slow you down.

0

精彩评论

暂无评论...
验证码 换一张
取 消