declare @value int
select @value = select aa from table1 where xyc = 'abc'
SELECT a.*,b.h1+b.h2 as h,b.xyc,b.ccz,b.xdd,b.yyc
INTO fees3
FROM fees a,fees2 b
where a.xx = b.xx and a.yy = b.yy and a.zz = b.zz
and (b.h1+b.h2) >= datediff(s,-@value,a.hh) and (b.h1+b.h2) < datediff(s,@value,a.hh)