Solved

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

Posted on 2004-08-19
4
138 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
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 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

832 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