Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

746 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

8 Experts available now in Live!

Get 1:1 Help Now