SQL 批量修改订单号

 1 declare @i int  
 2 set @i=0
 3 while @i<76
 4 begin
 5     DECLARE @NumBegin Int=1000000    --随机数的最小值
 6     DECLARE @NumEnd Int=10000000        --随机数的最大值
 7     DECLARE @Decimal Int=0        --保留小数点几位
 8     DECLARE @A Int= @NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)
 9     DECLARE @B Int= @NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)
10     DECLARE @NumBegin1 Int=10000    --随机数的最小值
11     DECLARE @NumEnd1 Int=100000        --随机数的最大值
12     DECLARE @Decimal1 Int=0        --保留小数点几位
13     DECLARE @C Int= @NumBegin1+round((@NumEnd1-@NumBegin1)*rand(),@Decimal)
14     DECLARE @AA varchar(50) =  CAST(@A AS varchar(50))
15     DECLARE @BB varchar(50) =  CAST(@B AS varchar(50))
16     DECLARE @CC varchar(50) =  CAST(@C AS varchar(50))
17     DECLARE @STR varchar(50) = @AA+@BB+@CC
18 
19     update [dbo].[Orders]
20     set OID = 'XNS'+@STR
21     WHERE  ID=@i+1
22 
23     update [dbo].[Orders_detail]
24     set OID = 'XNS'+@STR
25     WHERE  ID=@i
26 
27     set @i=@i +1
28 end
29 
30 select * from [dbo].[Orders]
31 select * from [dbo].[Orders_detail]

 

posted @ 2020-04-30 18:44  狂奔的胖切肯  阅读(313)  评论(0编辑  收藏  举报