I am using MS SQL Server 2017. Suppose I have two stored procedures SPA and SPB. They both take a parameter (e.g. both are integer parameters).
Is there any way to call SPA with a parameter value which would be passed to SPB for execution? Please see example below and it does not work. But this illustrates the idea. I got an error
Must declare the scalar variable "@param1"
I want 100 to be the value for @paramID1
when I run
EXEC SPB @paramID1 = @param1
Please advise. Thanks a million.
CREATE PROCEDURE SPA
@param1 INT
AS
INSERT INTO tbl
SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=(local);Trusted_Connection=yes;',
'EXEC SPB @paramID1=@param1') AS a
GO
-- Usage:
EXEC SPA @param1 = 100;