Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Comments
Thanks7872 25-Aug-14 8:10am    
Your previous question was closed because it doesn't make any sense. Posting it over and over again won't help you. Stop it or it will be considered Abuse.
Magic Wonder 25-Aug-14 8:25am    
A..gain Report it abuse and down vote the solution.
Thanks7872 25-Aug-14 8:55am    
I always downvote some thing which doesn't make any sense.
King Fisher 25-Aug-14 8:15am    
do you have any values in your Table upto 10000 Rows?

Try:
SQL
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)
 
Share this answer
 
If you access to master table

With out the loop

SQL
INSERT INTO Table_2 (Val)
SELECT distinct number
        FROM master..spt_values
        where number between 1 and 1000
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900