Skip to content Skip to sidebar Skip to footer

Sql Linked Server Query With Parameters

I need to select value from SQL Linked Server & get it to loacal variable This is what I've written so far: DECLARE @SQLQUERY AS VARCHAR(1000) DECLARE @FINALQUERY AS VARCHAR(10

Solution 1:

Instead of exec, use sp_execute_sql with an output parameter:

exec sp_executesql @FinalQuery, N'@OutVal output', @OutVal=@OutValout

Since sp_executesql expects nvarchar parameters, be sure to change the definition of @FinalQuery to nvarchar(max).

Solution 2:

@OutVal in query string does not recognized as a variable. use a function or return table statement.

Post a Comment for "Sql Linked Server Query With Parameters"