Solved

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

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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