How can I get the output of the below query in a variable without temp table?
DECLARE @Q1 NVARCHAR(300)
DECLARE @Q2 NVARCHAR(300)
DECLARE @Q3 NVARCHAR(300)
SET @Q1 = 'SELECT ' +' ' + @formfieldpath
SET @Q2 = 'FROM [TestDatabase].[details] WHERE id ' + '=''' + CAST(@id AS VARCHAR(10)) + '''';
SET @Q3 = @Q1 +' '+ @Q2
PRINT @Q3
EXEC sp_executesql @Q3
Tried 'How to get sp_executesql result into a variable?' and not able to get the results.