June 3, 2010 at 6:09 am
I'm working on a Silverlight / WCF project and I'm now in need of some SQL guidance from you people that know SQL inside out.
I have reached a point in the project where I need to give the user the ability to create certain calculations that is going to be used for validating all the data that goes into the database.
To give a short explanation:
- Table A contains data concerning electrical consumption
- Table B contains data concerning heat consumption
- The user adds a calculation [Table A].[Column 1] - [Table B].[Column 4] and a max value that this calculation may have. A service would later use this calculation to match it against the set max-value.
From my POW, this can me done in two ways, either store the calculations instruction-wise (eg. a table with all the necessary details that is needed for a service to fetch all the needed data and do the calculations off-site) OR one could create a view with computed columns which does this automatically.
Can someone please give me some pointers in which direction I should be going? Should I implement this the view-way (generate views through my application that does the calculations) or should I somehow store the instructions for the calculations in a table and use a service which does all the calculations and checks (would poll the database a lot more than going the view way).
Are there any other alternatives which I should take into consideration? Has anyone encountered this before and how have you solved it?
/Tobias
June 3, 2010 at 8:26 am
the devil is in the details, but here's my two cents:
use computed columns or a view which does the computation for you whenever possible.
i don't know if you've ever tried it, but storing a formula in a field, and then trying to execute the value of the field to get the results is a real pain in the... whatever.
try it with a simple example...
declare @MyCalculation varchar(30)
SET @MyCalculation ='SELECT 1 + 2+ 3'
EXEC (@MyCalculation)
--or worse COLUMNA + COLUMNB
see if you can get the results back...it's a pain.
Lowell
June 3, 2010 at 8:34 am
Thanks Lowell, I'll start working on using computed columns.
If anyone else pictures an even better way when reading this post, please share your ideas 🙂
June 3, 2010 at 2:45 pm
As Yogi Bera used to say, "When you come to a fork in the road, take it.". If you can suscessfully create a computed column, try to make it a "persisted" computed column.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply