Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Formula Calculation

Author  Topic 

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-03-25 : 05:54:04
I need to calculate dynamic formula change

Dummy values
Create table #A (id int,product nvarchar(25),values int)
insert into #A values ('1','Book','25')
insert into #A values ('2','Pen','30')
insert into #A values ('3','Eraser','10')

Formula Table
create table #Formulatable (FormulID int,FormulaName nvarchar(25),Formula nvarchar(max))
insert into #Formulatable ('1','FirstFormul','Book+Pen-Eraser')
insert into #Formulatable ('2','SeconFormul','Book+Pen*Eraser')

This above formula work fine for me
but when user update or change Formula like

update #Formulatable set Formula='Book+Pen-Eraser*SeconFormul' where
FormulaID=1

See in #Formulatable FormulaID 1 is updated by user and formula changed.This formula now having 2 level means formula with one more formula. How to solve this problem.
If this problem solved then I need n level calculation
(/*This all calculation done on flay so I am not going to save this calculated value in any other table*/)


Raghu' S

TheDarkPassenger
Starting Member

1 Post

Posted - 2011-03-25 : 12:43:34

Looks like you're making this difficult for yourself.

Ensure another formula line is created that has

Book+Pen-Eraser * Book+Pen*Eraser

and place a unique constraint on the Formula column to stop people entering duplicates.

HTH
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-03-28 : 08:29:29
Actually
In formula table Formula name is fixed
so we can't add any other additional row each time when formula edited through front-end.

Again in Formulatable column FormulaName is fixed user can edit only Formul.
(Note:1=
Actually I have more than 90 formulas in that many formula have sub formulas like
Example
1 st Formula Sum = A+B (where A and B are column of table)
2 nd Formula Sub = A-C (-------------do----------------)
3 rd Formula Mul = Sum*Sub ( Here sum is 1st fomrul and sub is 2nd)
)
In future user can change formula
as
1 st Formula Sum = D+C or D-C depending upon his requirement
so this is fully calculation based project.


Note :2
And this is on flay calculation so I am not going to store this result in any table

Raghu' S
Go to Top of Page
   

- Advertisement -