See if you want to set the exec value to your declare variable then you have to use sp_executesql on the following way
declare @query nvarchar(500)
declare @result varchar(20)
set @query=' select @cnt=Avg(value) from ihrawdata'
--Set the exec value to your declare variable
EXECUTE sp_executesql @query, N'@avg varchar(20) OUTPUT', @avg=@result OUTPUT
Select @result