I have a table-valued function in SQL Server and I am struggling to find a syntax for executing the function from my ServiceInterface class.
Is there any example of calling a table-valued function with multiple in parameters?
In SQL, the function can be executed:
--SQL function syntax:
DECLARE @BankAccountId UNIQUEIDENTIFIER
DECLARE @StartDate date
DECLARE @EndDate date
SET @BankAccountId = '91a98242-9ff0-ed21-9126-00165d017f21'
SET @StartDate = '2022-07-06'
SET @EndDate = '2022-10-01'
SELECT
*
FROM Bank.Ufn_AccountData(@BankAccountId, @StartDate, @EndDate)
I can workaround the problem by wrapping the SQL function inside an SQL stored procedure and executing it using the syntax:
private List<AccountEntry> GetAccountEntries(Guid accountId, DateOnly startDate, DateOnly endDate)
{
using var db = AutoQuery!.GetDb<AccountEntry>(Request);
using var cmd = db.SqlProc("Bank.Usp_Get_AccountData");
cmd.AddParam("BankAccountId", accountId);
cmd.AddParam("StartDate", IsoDateTimeHelper.ToDateTime(startDate));
cmd.AddParam("EndDate", IsoDateTimeHelper.ToDateTime(endDate));
var results = cmd.ConvertToList<AccountEntry>();
return results;
}