Solved

Output multiple records from one record using a query

Posted on 2003-11-17
6
299 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now