Return Multiple Records Based on Field Value

I'm trying to achieve the following within one query and without creating a "new" table (i.e. a table containing just numbers that I would do a LEFT JOIN <= on).  I would think there's a way to do a LEFT JOIN on itself, but I'm struggling to come up with the proper syntax.  Thoughts?

This post here is in line with what I'm trying to achieve, but I need to rely on solely the source table.  Is this achievable?

Source Table
ID|   Name   | Qty  
 1| Joe Smith|  3
 2| Bob Jones|  2

Open in new window

Expected Output
ID |   Name   | Qty | Item
 1 | Joe Smith|    3|    1
 1 | Joe Smith|    3|    2
 1 | Joe Smith|    3|    3
 2 | Bob Jones|    2|    1
 2 | Bob Jones|    2|    2

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Using a numbers or tally table is a common pattern. So just create one and use it.
Can you explain what your purpose is?  It doesn't make sense to just show the item number if there are no details of each item.  Now if you do have a table with the details of each transaction, then why not just join the two tables?

fijijimsAuthor Commented:
Ste5an... Creating one is not an option for the environment I am working in.

IrogSinta... This will be the foundation to how I link it to the table that stores the detail.  But the detail does not necessarily have a corresponding record for each item.  I need to display in the output the items that have assignments, as well as those that are "open".
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ste5anSenior DeveloperCommented:
Sorry, but your expected output can only be acheived be a Cartesian JOIN with a number table in any form.

So either you use one or you review your requirements.
But the detail does not necessarily have a corresponding record for each item.
What exactly do you mean by this?  Can you post some sample data from the details table you have?  Maybe that will clear it up a bit.
fijijimsAuthor Commented:
Sample detail for Joe Smith that would apply would be...

Source Parent Table
ID|   Name   | Qty  
 1| Joe Smith|  3

Open in new window

Source Assignment Table
ID |   Name   | Qty | Assignment
 1 | Joe Smith|    1| Designee ABC 
 1 | Joe Smith|    1| Designee DEF 

Open in new window

This table is a 1-to-Many based on Inner Join of the ID field to the first table.  I'm trying to create a view that shows where we have "open" assignments (i.e. record count [or sum of qty, which will always be 1] based on the inner join of the assignment table where the count (or sum) is less than the QTY field of the main table.

Expected Output
ID |   Name   | Qty | Item | Assignment
 1 | Joe Smith|    3|    1 | Designee ABC
 1 | Joe Smith|    3|    2 | Designee DEF
 1 | Joe Smith|    3|    3 | <Open> (or null value here would be fine)

Open in new window

Gustav BrockCIOCommented:
You can use an existing table to create a number list:
    [Tens]+[Ones] AS Factor, 
    10*Abs([Deca].[id] Mod 10) AS Tens, 
    Abs([Uno].[id] Mod 10) AS Ones
    msysobjects AS Uno, 
    msysobjects AS Deca;

Open in new window

Save as, say, qdyFactor

Now, create a query with a Cartesian join:
    Factor As [Item]
    Factor <= Qty

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It still isn't clear to me where you are going with this.  What you are asking to do is easy enough with a count table.  However, the Cartesian Product solutions will result in a non-updateable recordset and so will not work if you intend to use them as the RecordSource of a form for update or data entry.

Doing the join as you request, will bring back some number of "empty" rows but what is the point?  Subforms allow an infinite number of rows to be added/updated.  If you want to control the number of subform records added, then in the BeforeInsert event of the subform, use DCount() to count the number of existing rows for this set and if it is <= the number that already exist, cancel the BeforeInsert event to prevent the user from adding additional rows.
fijijimsAuthor Commented:
I'm trying to understand the SQL to make it happen or, more so, if it is possible at all.

It is to create a table-based extract to be used in a different tool.

The environment I am working in does not provide me with provisioning to create tables, so I am limited to working with the datasets that are created within the given SQL statements I am writing.
Gustav BrockCIOCommented:
Then the listed methods will work. Just export the output to your different tool.

ste5anSenior DeveloperCommented:
You can create always tables in Access? What is you problem? Have you never used temporary tables in a temporary database file?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.