?
Solved

HELP ASAP - Insert records in Table B based on data from Table A

Posted on 2004-08-19
4
Medium Priority
?
143 Views
Last Modified: 2010-05-02
Need to use data in a single field in each record in Table A and insert records in table B based on that data....

Table A:
Field1  Text
Field2  Date
Field3  Int

Table A example record:
Williams    01/01/2004    3

Table B
Field1  Text
Field2  Date
Field3  Int

Table B example records created from example record in Table A:
Williams    01/01/2004    1
Williams    01/01/2004    2
Williams    01/01/2004    3

Essentially I want to insert X records into Table B data from Table A where X = Field3

Please help!



0
Comment
Question by:RedOakPackster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 11848214
Which database are you using?
0
 

Author Comment

by:RedOakPackster
ID: 11848222
MS SQL Server 2000
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 11848601
How about this?  I'm not sure whether you're just looking for the logic or the specific code to accomplish what you described.  As a result of that and not knowing what approach you're using to access the databases, I've only provided pseudo-code.

While Not File1.EOF()
    intRecsToAdd = TableA.Field3
    For intCounter = 1 To intRecsToAdd
        TableB.AddRecord
    Next
Wend
0
 
LVL 7

Expert Comment

by:Enlade
ID: 11848949

There is no SQL statement that I can think of that would let you do that (if that is what you are asking).  You will need to do something programmatically like BlueDevilFan is suggesting

Heres more pseudo-code:

For i = 1 to Number of Records in Table A
  For j = 1 to Value of TableA.Field3
    Add New Record to TableB such that
      TableB.Field1 = TableA.Field1
      TableB.Field2 = TableA.Field2
      TableB.Field3 = j
  Next j
Next i

But it is essentially the same thing that BlueDevilFan is saying.  It should be easy enough to implement.  If you know how to read a record from the database and if you know how to write a new record to the database then that is all you need to know.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

719 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