Bulk inserting

  • First of all, apologies if I do not explain myself properly.

    I have to do an insert to a table and one of the fields has to be populated by the value from another table. Lets say the tables are:

    MyTable1

    MyDiscount

    MyProduct

    MyTable2

    Product

    So I'm going to pass the discount value and I want the discount to be inserted into MyTable1 FOR EACH product from MyTable2.

    Now the obvious and lazy thing (I'm doing this in Visual Basic) is to get all the records into a recordset and loop round, inserting each record as I go...but there must be a more efficient way, right?

    Is it

    Insert into MyTable1 (MyDiscount,MyProduct) Values (@Discount, Product) Select Product from MyTable2

    ??

    Thx for your help

  • It's ok...I've worked it out.

    Insert into MyTable1 (MyDiscount,MyProduct) Select @discount,Product from MyTable2

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply