I have a function fn_test
with 3 parameters. Then I define a stored procedure to use this function. As it is a function on a linked server, I use openquery
to call it. The problem is that I do not know how to pass parameters to the function in openquery
.
The stored procedure is as follow
CREATE PROCEDURE [cmn].[sp_Agent_Karmozd]
AS
BEGIN
DECLARE @CurrentDate TDate = '2020/01/01
INSERT INTO dbo.cmn_Agent_Karmozd
SELECT *
FROM OPENQUERY ([DWH], 'select * from fn_test (null, null, @CurrentDate) ')
END
Executing the script I get this error:
Msg 8180, Level 16, State 1, Line 11
Statement(s) could not be prepared.Msg 137, Level 15, State 2, Line 13
Must declare the scalar variable "@CurrentDate"