I am getting the error "Must declare the scalar variable "@Result"" when i execute the below query
declare @sql nvarchar(max),
@Id int,
@Result int
set @tablename='xyz'
set @id=1
SET @sql = '
SELECT @Result=COUNT( Id ) FROM ' + @TableName+ ' WHERE RunRegisterKey=' +convert(nvarchar(100),@ID)
EXEC sys.sp_executesql @sql