You need to assign the result of selecting variable inside the Dynamic statement .
Modify the query this way.
DECLARE @Result NVARCHAR(MAX) DECLARE @Qry NVARCHAR(MAX) SET @Qry='SELECT @Result = Test FROM MTest22Dec WHERE ID = 1' EXECUTE Sp_executesql @Qry, N'@Result NVARCHAR(MAX) OUTPUT', @Result OUTPUT PRINT @Result
source share