Repeating rows with same data

R

rama

Hello
I am looking for some help to make query which can append 60 rows in a
table with same data.
I have a table called tblName, which contains unique names. I need to
append each of these names to 60 rows in another table called
tblDetail. (INSERT INTO tblDetails (Name ) SELECT tblName.Name FROM
tblName;) With this query I can append “name” to one row in tblDetails
at a time. How can I make it 60 times. Please help me to overcome
this.
Rama
 
B

Bob Barrows [MVP]

rama said:
Hello
I am looking for some help to make query which can append 60 rows in a
table with same data.
I have a table called tblName, which contains unique names. I need to
append each of these names to 60 rows in another table called
tblDetail. (INSERT INTO tblDetails (Name ) SELECT tblName.Name FROM
tblName;) With this query I can append “name” to one row in tblDetails
at a time. How can I make it 60 times. Please help me to overcome
this.
Rama

Simple answer: Run the query 60 times
..
Slightly more complex: Perhaps use a loop in a VBA procedure

More complex: use a union query repeated 60 times:
INSERT INTO tblDetails (Name )
SELECT tblName.Name FROM tblName
union all
SELECT tblName.Name FROM tblName
union all
SELECT tblName.Name FROM tblName
.... repeat until you have 60 selects unioned together

More complex: Do a cross join with a table containing 60 rows, perhaps a
table of numbers from 1 to 60. Call it tblNumbers with a field called
[Number].

INSERT INTO tblDetails (Name )
SELECT tblName.Name FROM tblName,tblNumbers
WHERE tblNumbers.[Number] <= 60
 
R

rama

rama said:
Hello
I am looking for some help to make query which can append 60 rows in a
table with same data.
I have a table called tblName, which contains unique names. I need to
append each of these names to 60 rows in another table called
tblDetail. (INSERT INTO tblDetails (Name ) SELECT tblName.Name FROM
tblName;) With this query I can append “name” to one row in tblDetails
at a time. How can I make it 60 times. Please help me to overcome
this.
Rama

Simple answer: Run the query 60 times
.
Slightly more complex: Perhaps use a loop in a VBA procedure

More complex: use a union query repeated 60 times:
INSERT INTO tblDetails (Name )
SELECT tblName.Name FROM tblName
union all
SELECT tblName.Name FROM tblName
union all
SELECT tblName.Name FROM tblName
... repeat until you have 60 selects unioned together

More complex: Do a cross join with a table containing 60 rows, perhaps a
table of numbers from 1 to 60. Call it tblNumbers with a field called
[Number].

INSERT INTO tblDetails (Name )
SELECT tblName.Name FROM tblName,tblNumbers
WHERE tblNumbers.[Number] <= 60

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Thanks for the help. I choose the last option and my append query is
fine now.
Rama
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top