Solved

Output multiple records from one record using a query

Posted on 2003-11-17
6
302 Views
Last Modified: 2009-07-29
Is it possible to output more than one record from each record read into a query?

ie) if I have an append query that reads tableA, I want to append 4 records to tableB from each record in tableA using different fields from table A

If not in a query is there another way....keeping in mind I am pretty new to all this?

This is the SQL view of my query so far....

INSERT INTO [Tee Time Analysis Table] ( [Date], [Tee Time], [Member No], [Member Name], Comments, [Member Type] )
SELECT [Tee Times].[Todays date], [Tee Times].[600], [Tee Times].[600m1no], [Tee Times].[600m1], [Tee Times].[600comments], Mid([600m1no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m1no]) Is Not Null));

I would like the same info for 600m2no, 600m3no and 600m4no
0
Comment
Question by:m4moi
  • 3
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
gajender_99 earned 50 total points
ID: 9769764
hi try this

INSERT INTO [Tee Time Analysis Table] ( [Date], [Tee Time], [Member No], [Member Name], Comments, [Member Type] )
(
SELECT [Tee Times].[Todays date], [Tee Times].[600], [Tee Times].[600m1no], [Tee Times].[600m1], [Tee Times].[600comments], Mid([600m1no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m1no]) Is Not Null))
union
SELECT [Tee Times].[Todays date], [Tee Times].[600], [Tee Times].[600m2no], [Tee Times].[600m1], [Tee Times].[600comments], Mid([600m1no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m2no]) Is Not Null))
union
SELECT [Tee Times].[Todays date], [Tee Times].[600], [Tee Times].[600m3no], [Tee Times].[600m1], [Tee Times].[600comments], Mid([600m3no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m3no]) Is Not Null))
union
SELECT [Tee Times].[Todays date], [Tee Times].[600], [Tee Times].[600m4no], [Tee Times].[600m1], [Tee Times].[600comments], Mid([600m4no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m4no]) Is Not Null))
):

try this
0
 

Author Comment

by:m4moi
ID: 9769851
gajender_99

i get a "syntax error in INSERT INTO error" and the cursor is put at the ( just below INSERT INTO
0
 
LVL 28

Expert Comment

by:TextReport
ID: 9769909
I would execute 4 different queries, much simpler and as quick as unions.

Cheers, Andrew
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 8

Expert Comment

by:gajender_99
ID: 9770393
hi sorry for that i missed 1 line now try this

INSERT INTO [Tee Time Analysis Table] ( [Date], [Tee Time], [Member No], [Member Name], Comments, [Member Type] )

Select todays_date,600,mno,mno1,mcomment,expr1
From (
SELECT [Tee Times].[Todays date] as todays_date, [Tee Times].[600] as 600, [Tee Times].[600m1no] as mno, [Tee Times].[600m1] as mno1, [Tee Times].[600comments] as mcomment, Mid([600m1no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m1no]) Is Not Null))
Union
SELECT [Tee Times].[Todays date] as todays_date, [Tee Times].[600] as 600, [Tee Times].[600m2no] as mno, [Tee Times].[600m1] as mno1, [Tee Times].[600comments] as mcomment, Mid([600m2no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m2no]) Is Not Null))
Union
SELECT [Tee Times].[Todays date] as todays_date, [Tee Times].[600] as 600, [Tee Times].[600m3no] as mno, [Tee Times].[600m1] as mno1, [Tee Times].[600comments] as mcomment, Mid([600m3no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m3no]) Is Not Null))
Union
SELECT [Tee Times].[Todays date] as todays_date, [Tee Times].[600] as 600, [Tee Times].[600m4no] as mno, [Tee Times].[600m1] as mno1, [Tee Times].[600comments] as mcomment, Mid([600m4no],2,1) AS Expr1
FROM [Tee Times]
WHERE ((([Tee Times].[600m4no]) Is Not Null))
);
0
 

Author Comment

by:m4moi
ID: 9772327
gajender_99

this gives me a "syntax error in FROM clause"
0
 

Author Comment

by:m4moi
ID: 9806410
gajender_99

i'll give you the points anyways but I had to take the INSERT INTO part out and make the query a select query and then append the results of that into my table....that saved me some work but would have been nice to make the Insert part work too
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

860 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