Display a data set x times

cheberdy

Member
Local time
Today, 23:16
Joined
Mar 22, 2023
Messages
77
Is there a way to create a query ,that does the following. There is a table with column name, identification number and a quantity. The query should represent the name and identifiaction number. Both should be representet quantity times.
 
You may be able to use a Tally table and a Cartesian Query to get what you want.
 
@cheberdy You're new here. Welcome. Your question is unclear. Can you give us an example of the data you have and the results you want.
 
@cheberdy You're new here. Welcome. Your question is unclear. Can you give us an example of the data you have and the results you want.
This is my table
name ________id_________quantity
car____________1__________5

The query should do this
name ________id
car____________1
car____________1
car____________1
car____________1
car____________1
 
What's your ultimate goal? Based on your example above, do you want 5 records in a table?
 
Here's an example query using a Tally table.
SQL:
SELECT [name], id
FROM TableName, TallyTable
WHERE TallyTable.ID<=TableName.quantity
(untested)
Hope that helps...

Edit: Fixed SQL. Thanks to @CJ_London for spotting the error.
 
Last edited:
@theDBguy - think you meant

Code:
SELECT [name], id
FROM TableName, TallyTable
WHERE TallyTable.ID<=TableName.quantity

The tally table ID's need to run consecutively from 1 to at least whatever number is big enough for the maximum quantity in your quantity field
 
@theDBguy - think you meant

Code:
SELECT [name], id
FROM TableName, TallyTable
WHERE TallyTable.ID<=TableName.quantity

The tally table ID's need to run consecutively from 1 to at least whatever number is big enough for the maximum quantity in your quantity field
How do I create this tally tabel
 
Here's an example query using a Tally table.
SQL:
SELECT [name], id
FROM TableName, TallyTable
WHERE TallyTable.ID<=TableName.id
(untested)
Hope that helps...
How do I create a tally table in access
 
Maybe something like
Declare i as Integer
Select mytable.Quantity
from mytable
while mytable.Quantity < i
Begin
Select mytable.Id, mytable.name from mytable
Set i = i+1
End
 
@theDBguy - think you meant

Code:
SELECT [name], id
FROM TableName, TallyTable
WHERE TallyTable.ID<=TableName.quantity

The tally table ID's need to run consecutively from 1 to at least whatever number is big enough for the maximum quantity in your quantity field
Haha, good thing I said "(untested)." :LOL:

Thanks for the assist! 👍
 
Maybe something like
Declare i as Integer
Select mytable.Quantity
from mytable
while mytable.Quantity < i
Begin
Select mytable.Id, mytable.name from mytable
Set i = i+1
End
But you never set what i is??? :(
Why not go with the simple solution the experts supplied? :(
 
Another less efficient method would be using a temp table.


p1.png


p2.png
 

Users who are viewing this thread

Back
Top Bottom