declare @station int
update 表 
set 
    @station=isnull(@station,0)+isnull(station,0),
    station=@station

解决方案 »

  1.   

    create table a (a varchar(10),b int)
    insert into a select '起始站',3
    insert into a select '第一站',1
    insert into a select '第二站',null
    insert into a select '第三站',null
    insert into a select '第四站',2
    insert into a select '第五站',null
    insert into a select '第六站',null
    insert into a select '终点站',null
    create table b (a varchar(10),b int,c int identity)
    insert into b select *
    from a
    select a,b=(select sum(b) from b where t.c>=b.c)
    from b t
    drop table b
    drop table a
      

  2.   

    create table a (a varchar(10),b int)
    insert into a select '起始站',3
    insert into a select '第一站',1
    insert into a select '第二站',null
    insert into a select '第三站',null
    insert into a select '第四站',2
    insert into a select '第五站',null
    insert into a select '第六站',null
    insert into a select '终点站',nulldeclare @station int
    update a set @station=case a when '起始站' then b else isnull(@station,0)+isnull(b,0) end,b=@stationselect * from adrop table a
    /*a          b           
    ---------- ----
    起始站        3
    第一站        4
    第二站        4
    第三站        4
    第四站        6
    第五站        6
    第六站        6
    终点站        6 */