I have been tasked with writing a stored procedure that takes a user specified formula as parameter, and does calculations using tables on the formula.
It’s for the result of a competency test. The test is broken up into sections and each section is assigned a variable, eg. E1 and E2.
Now each section consists of questions with their scores. eg. E1 = [1]+[2]-[3]+[4]+[5]+[6] when the [number] indicates the question number.
Now the user will specify a formula like the above [1]+[2]-[3]+[4]+[5]+[6], and I have to write a parser that replaces the question number with the score for that question. But there is a snag in it, because one section can reference the score of another section eg. E2 = [7]+[8]+([6]-E1)+[9].
So I need to write a parser that parses the string, replaces the [Number] with the score, and if it hits a variable number, first calculates the sections score, before continuing.
I can imagine that it will be something like a recursive function, but can anyone help me oin the right direction?
Kind Regards.
I’m not saying you can’t do it, but SQL is not the best environment for this kind of operation; equally, you can bash a nail into a wall using a watermelon. You don’t specify your particular platform – if it is Microsoft SQL then perhaps a SQL CLR procedure would make the necessary manipulations easier.