34,588
社区成员
发帖
与我相关
我的任务
分享
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 行)
*/