I have a table valued function.Within that function i have a this code
DECLARE @totalPayment DECIMAL(18,4)
DECLARE @totalPaymentConverted DECIMAL(18,4)
DECLARE @fromCurrencyIdForPaymentSystemsId CHAR(3)
DECLARE @GetTotalPaymentAmount AS TABLE
(
Amount DECIMAL(18,4),
CurrencyId CHAR(3)
)
INSERT INTO @GetTotalPaymentAmount
SELECT SUM(Amount),CurrencyId
FROM [dbo].[fn_DepositWithdrawReport]()
WHERE OperationTypeId = 2
GROUP BY CurrencyId
This insert return met table like this
A C
-----|------
550 |USD
650 |EU
|
I want to pass each of this values Amount and CurrencyId to the Scalar valued Function as Input parameter like this
[dbo].[function_Valued](@totalPayment,@fromCurencyId,@toCurrencyId)
And sum that values for instance if we consider the table above
[dbo].[functin_scalar](550,USD,EU)=450
[dbo].[function_scalar](650,EU,EU)=650
Get total 1100
Put simply i want calculate sum amount and i need to convert it in one currency.