declare @i int
declare @sourceid int
declare @tempid int
set @sourceid=0
--循环变量
set @i=0
while @i<20
begin
--订单快递id为动态变量
set @tempid=( select top 1 tid from sys_typelib where tpid=1 and tid>@sourceid order by tid)
set @sourceid = @tempid
--插入的订单号是从现有的订单表获取的最大订单号+1
insert into order_info (sourceid,ordertypeid,ordercode,packnum,statusid,intime,isneworder)
select @sourceid,58,CONVERT(bigint,ordercode)+1 ,1,6,GETDATE(),1
from
order_info where orderid= (select MAX(orderid) from order_info)
set @i=@i+1;
end
declare @sourceid int
declare @tempid int
set @sourceid=0
--循环变量
set @i=0
while @i<20
begin
--订单快递id为动态变量
set @tempid=( select top 1 tid from sys_typelib where tpid=1 and tid>@sourceid order by tid)
set @sourceid = @tempid
--插入的订单号是从现有的订单表获取的最大订单号+1
insert into order_info (sourceid,ordertypeid,ordercode,packnum,statusid,intime,isneworder)
select @sourceid,58,CONVERT(bigint,ordercode)+1 ,1,6,GETDATE(),1
from
order_info where orderid= (select MAX(orderid) from order_info)
set @i=@i+1;
end
本文介绍了一个使用SQL进行批量插入新记录,并通过查询现有最大订单ID来确定新订单号的方法。该过程通过循环实现了20次的迭代操作。
5085

被折叠的 条评论
为什么被折叠?



