-- I have a query that is stored in a table column, the query contains a parameter
-- I tried to pass the parameter, but failed. How can I accomplish this task?
CREATE TABLE #testFullQuery(longString varchar(Max))INSERT INTO #testFullQuery(longString) VALUES ('SELECT * FROM @NewValue');
DECLARE @SourceCode nvarchar(MAX);
SELECT @SourceCode = longString FROM #testFullQuery
DECLARE @NewValue VARCHAR(MAX) = 'TableName';
DECLARE @FullQuery nvarchar(MAX);
SET @FullQuery = '';
SET @FullQuery = @SourceCode
EXEC sp_executesql @FullQuery;
print @fullQuery, @NewValue
l__j