I have an T-SQL script where I'm fetching results from the OPENROWSET
function, like this:
DECLARE @TableForBalance TABLE
(
--fields
)
DECLARE @Param varchar(15) = 'XXXXXXX'
DECLARE @query varchar(255) = CONCAT('EXEC SomeStoredProcedure ''',@Param,'''')
INSERT INTO @TableForBalance select * FROM OPENROWSET('SQLNCLI', 'Server=10.10.10.10;Trusted_Connection=yes;', @query)
and I'm getting a tip:
Incorrect syntax near '@query'. Expecting '.', ID, QUOTED_ID, STRING or TEXT_LEX
But when I do something like:
INSERT INTO @TableForBalance select * FROM OPENROWSET('SQLNCLI', 'Server=10.10.10.10;Trusted_Connection=yes;', 'EXEC SomeStoredProcedure ''XXXXX''')
it works, but I want the @Param
to be dynamic.
Any solution ?? Thanks