473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Query to loop through data and append to table

Hi,

I’m just starting a database that will contain historical data of all the conferences that our employees have attended over the years. I have 3 tables (Employees, Conferences, and the 3rd is Attendance which has the EmployeeID and ConferenceID). Everything works great with my test data, but now I need to import from our existing spreadsheet of 700 Employees and 250 Conferences. I appended the employees to the Employee table and the conferences to the Conference table. Now I’m trying to figure out a query that I can run to append the EmployeeID and ConferenceID to the attendance table, based off of my existing spreadsheet.

The spreadsheet is set up like:
Expand|Select|Wrap|Line Numbers
  1.         Conference_A  Conference_B  Conference_C
  2. Jane Doe         y                           y
  3. John Doe                       y             y
  4. Mary Doe         y
Can anyone recommend a way to set up my query so it will go through each record and attend the ID’s to my Attendance table? I found that if I replace the “y” in each column with the full name of the Conference, then I can do an update query for that one event. But going through and manually changing first the “y” to the Conference, and then changing the query event, will take many, many hours. Is there any easier way that I’m missing? Maybe some sort of loop query (though I don’t know anything about those)?

Thanks for your help!

- Katie
Nov 16 '10 #1
1 1978
NeoPa
32,556 Expert Mod 16PB
Working from the example data, in Excel, I would create a formula in a set of cells just to the right of row #2 (Assuming the current example data has TopLeft of A1 and BottomRight of D4, that would be at E2).
Expand|Select|Wrap|Line Numbers
  1. =IF(B2="Y",$A2 & CHAR(9) & B$1,"Empty")
This formula could then be duplicated by copying this cell and pasting across a range that covers all the rows (from #2 to the end) and a matching number of columns (in this case E through G).

This done, copy the whole new range to the clipboard (Ctrl-C) and use Edit / Paste Special / Values into a completely new workbook. This will produce data with all the "Y"s replaced with a reference which includes the names of both the employee as well as the conference. It also leaves the empty cells as "Empty" though, so from here select the new data range again if necessary (A1 through C3 of the new workbook) and do a Replace (Ctrl-H) of the word "Empty" with a blank value in the Replace with: box. This will remove these entries.

The next job is to move (Cut (Ctrl-X) and Paste (Ctrl-V)) the data from columns B through the last one down to the bottom of column A. Essentially consolidating all the data into a single column. A sort would be helpful next. This will ensure all blank cells are left at the end and need not be included in the saved workbook (Check when done that Ctrl-End finds the last cell with data in after saving the new workbook. If it doesn't, then select all rows below those that contain data and choose Delete from the Right-click menu).

You now have a workbook that can be imported into your table to produce the requisite data using an append query.

Let us know how you get on with this and welcome to Bytes!
Nov 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: CSN | last post by:
I have a pretty simple select query that joins a table (p) with 125K rows with another table (pc) with almost one million rows: select p.* from product_categories pc inner join products p on...
1
by: grlgeek | last post by:
I've got a database for creating cost estimates for construction jobs. Within the database there are 2 tables 1. ProjectIdentifier Table 2. CostEstimate Table The relationship is a 1 to...
4
by: Joe-Paul | last post by:
Hi: I'm running a simple query on an Access Table from VB6.0. The operator can make several different selections. Based on their selection, a different, specific SQL needs to be run. So, when...
1
by: Ya Ya | last post by:
I am using the personalization feature in asp.net 2.0 I am storing the phone number for each user. When a certain user enters his phone number I would like to check if another user already...
2
by: gaston | last post by:
Hi All I have three data bases with a table each one, what I want to do is to get the data from each table and insert it in a new data base table. The thing is that may be there is going to a...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
2
by: scolivas | last post by:
Is there a way to automate this process? I have a query that finds the "Drop Offs" by doing an unmatch query against the hard table and the live table. I want to automatically pull these...
4
by: AppDev63 | last post by:
I have a table with a location ID; multiple locations per ID. I need to loop throught that table and create new tables for each location ID so that I can send a report out to each location,...
0
by: Filio | last post by:
Hi all: My problem is a little different than the earlier append table post. I have T1 with an autonum field as the primary key, and T2 with identical fields as the first, but no autonum. ...
1
by: rahullko05 | last post by:
Hi, i am building a small forum site as my final year project & stuck in a very trivial problem. I have a table which are varchar type of data & i am trying to fetch data from table based on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.