-- 逐行计算、逐行递延、逐行更新

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, 终止号=@end
select * from @tb

/*工号        姓名        数量        基数        开始号      终止号         
----------- ---------- ----------- ----------- ----------- ----------- 
1           张三         5           100         101         105
2           李四         6           105         106         111
3           王五         7           111         112         118

(所影响的行数为 3 行)
*/



相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
  • 2021-08-22
猜你喜欢
  • 2022-01-14
  • 2022-02-25
  • 2021-10-25
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
相关资源
相似解决方案