DECLARE @ParmDefinition nvarchar(500)=N'@retvalOUT VARCHAR(500) OUTPUT',@retval VARCHAR(500)
DECLARE @SqlTxt NVARCHAR(MAX)='Put your SQL Query here';
EXECUTE sp_executesql @SqlTxt, @ParmDefinition, @retvalOUT=@retval OUTPUT;
Select @retval; --It worked for me to get output
You can modify it according to your's requirement