create proc forecast  --计算趋势
 @firstday datetime,
 @lastday datetime,
 @b float(4) output,--输出趋势
 @d float(4) output
as
declare @q float(4)
declare @n int,@tt int,@avgt int
declare @dt float
declare @T int,@TD int
  set @n=datediff(dd,@firstday,@lastday)+1
  set @tt=(1+@n)*@n/2
  set @avgt=@tt/@n while @firstday<=@lastday
 begin
  select @q=销售量/季节性系数 from sales
  where 销售日期=@firstday
  update sales_1
  set Dt=@q 
  where 销售日期=@firstday
  set @firstday=@firstday+1
 endwhile @firstday<=@lastday
 begin
  select @dt=DT from sales_1
  where 销售日期=@firstday 
  select @d=avg(Dt) from sales_1
  update sales_1
  set TD=(@n-1-@avgt)*(@dt-@d),T=(@n-1-@avgt)*(@n-1-@avgt)
  /*问题在这段,在执行完存储过程后T可以显示我要的结果了,但是TD那列,值是NULL*/  
  where 销售日期=@firstday
  set @firstday=@firstday+1
  set @n=@n-1 
 endselect @T=sum(T) from sales_1
select @TD=sum(TD) from sales_1
set @b=@TD/@T
go我搞不懂两个都差不多啊?为什么TD那列值都是NULL。