有表如下
工号 姓名 数量 基数 开始号 终止号
1 张三 5
2 李四 6
3 王五 7

比如基数是100,希望得到结果:

工号 姓名 数量 基数 开始号 终止号
1 张三 5 100 101 105
2 李四 6 105 106 111
3 王五 7 111 112 118现在表内的数据非常多,希望有简单的方法配置。请问应该怎么设置?
表在附件里,多谢。

解决方案 »

  1.   

    declare @tb table(工号 int, 姓名 nvarchar(10), 数量 int, 基数 int, 开始号 int, 终止号 int) insert @tb(工号, 姓名, 数量) select 1, N'张三', 5 
    insert @tb(工号, 姓名, 数量) select 2, N'李四', 6 
    insert @tb(工号, 姓名, 数量) select 3, N'王五', 7 
    declare @num int,@begin int,@end int
    select  @num=0
    update @tb set @num=case when @num=0 then 100 else @end end,@begin=@num+1,@end=@num+数量,
    基数=@num,开始号=@begin,终止号=@endselect * from @tb/*
    工号        姓名        数量        基数        开始号      终止号         
    ----------- ---------- ----------- ----------- ----------- ----------- 
    1           张三         5           100         101         105
    2           李四         6           105         106         111
    3           王五         7           111         112         118(所影响的行数为 3 行)
    */
      

  2.   

    其实,利用EXCEL进行处理,也不错。
    一楼的话,你要把数据导入到数据库表里,然后再执行SQL语句。
      

  3.   

    学习,方法真的不错。declare @tb table(工号 int, 姓名 nvarchar(10), 数量 int, 基数 int, 开始号 int, 终止号 int) insert @tb(工号, 姓名, 数量) select 1, N'张三', 5 
    insert @tb(工号, 姓名, 数量) select 2, N'李四', 6 
    insert @tb(工号, 姓名, 数量) select 3, N'王五', 7 
    declare @num int,@begin int,@end int
    select  @num=0
    update @tb set @num=case when @num=0 then 100 else @end end,@begin=@num+1,@end=@num+数量,
    基数=@num,开始号=@begin,终止号=@endSELECT * FROM @tb