Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

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

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
RedOakPackster
Asked:
RedOakPackster
1 Solution
 
JR2003Commented:
Which database are you using?
0
 
RedOakPacksterAuthor Commented:
MS SQL Server 2000
0
 
David LeeCommented:
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
 
EnladeCommented:

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now