I have 2 tables in SQL Server, with
DECLARE @Formulas TABLE (ID int, Calculation varchar(max))
INSERT INTO @Formulas
VALUES (1, '([445660][SOLDE]+[401000][DEBIT]-[380100][CREDIT])')
DECLARE @Values TABLE (ValueID int, Solde money, Debit money, Credit money)
INSERT INTO @Values
VALUES (445660, 2500, 5500, 3000),
(401000, 0, 2500, 0),
(380100, 0, 0, 3500.24)
DECLARE @SQL varchar(max)=''
SELECT @SQL = @SQL+concat(',(',ID,',',Calculation,')') From @Formulas --Where ID=2
SELECT @SQL = Replace(@SQL,'['+cast(ValueID as varchar(25))+']',/[Value]/) From @Values
SELECT @SQL = 'Select * From ('+Stuff(@SQL,1,1,'values')+') N(ID,Value)'
EXEC(@SQL)
The /[Value]/ in the 3 code must change to column (Solde, Debit, Credit) because I have 3 columns, and the user can choose any of them.
I take a example Calculating/Evaluate user defined formula with SQL but it is with single column
Thanks in advance.