SQL Command

Posted on 2011-02-24
Last Modified: 2012-05-11
How can I insert 50 records in a table as follows using sql command.

ItemNo(varchar)   name (varchar)
A_1                       some Text
A_2                       some Text
A_50                     some Text

Question by:ayha1999
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34972781
declare @No integer
set @No = 1

while @No <= 50
  insert into table1(ItemNo, name)
  select 'A_1' + cast(@No as varchar), 'some text'
  set @No = @No + 1
LVL 32

Accepted Solution

Ephraim Wangoya earned 250 total points
ID: 34972786
declare @No integer
set @No = 1

while @No <= 50
  insert into table1(ItemNo, name)
  select 'A_' + cast(@No as varchar), 'some text'
  set @No = @No + 1

Open in new window

LVL 20

Expert Comment

ID: 34972821
U could also take a look at SqlBulkCopy, which is quite fast.
LVL 41

Expert Comment

ID: 34973399
You can try CTE.
declare @table as table (StartValue int, EndValue int)
insert into @table values (1,10) -- change this number to required value
;with CTE as (
select StartValue,EndValue from @table union all
select StartValue+1,EndValue from CTE where StartValue+1 <= EndValue)
select 'A_'+CONVERT(varchar,StartValue) ItemNo,'some text' name 
  from CTE
ItemNo	name
A_1	some text
A_2	some text
A_3	some text
A_4	some text
A_5	some text
A_6	some text
A_7	some text
A_8	some text
A_9	some text
A_10	some text

Open in new window


Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question