更新时间:2023-01-29 11:09:24
尝试:DECLARE @ Start int
DECLARE @ End int
选择 @ Start = 1,@ End = 10000
; WITH 序列(数字) AS
(
SELECT @开始 AS 编号
UNION ALL
SELECT 数字+ 1
FROM 序列
WHERE 数字< @ End
)
INSERT INTO 表_2(Val)
SELECT * FROM 序列 选项(MaxRecursion 10000 )
如果你访问主表
没有循环INSERT INTO 表_2(Val)
SELECT distinct number
FROM master。 .spt_values
其中编号 1 和 1000lockquote>
Hi Experts,
I have a table with name SerialNoInfo, In this table I want to Insert Numbers from 0001 to 10000 into Column(Serialno) by using sql query.
for example as:
0001
0002
0003
0004
0005
0006
.
.
.
.
.
.
.
10000
Please help me.
Thanks.Try:DECLARE @Start int DECLARE @End int Select @Start=1, @End=10000 ;WITH Sequence( Number ) AS ( SELECT @start AS Number UNION ALL SELECT Number + 1 FROM Sequence WHERE Number < @End ) INSERT INTO Table_2 (Val) SELECT * FROM Sequence Option (MaxRecursion 10000)
If you access to master table
With out the loopINSERT INTO Table_2 (Val) SELECT distinct number FROM master..spt_values where number between 1 and 1000