INSERT query

  • Hi

    I have a Table1 with the following fields

    RELATEDRECORDIDINT

    FIELDIDINT

    SOURCERECORDID INT

    I need to add into TABLE1 a record for each of the rows that match the following criteria

    SELECT ID FROM TABLE2 WHERE PROJECTID IN (18, 26, 20, 22, 35, 38, 148, 149, 155, 278)

    So, given the above select statement, for each ID it returns I need to add a record in the TABLE1 table with the following:

    RELATEDRECORDID1

    FIELDID614

    SOURCERECORDIDEach value returned from the select statement above

    Any help you can give me is going to be very much appreciated!!!

  • INSERT TABLE1

    SELECT 1,614,ID

    FROM TABLE2

    WHERE PROJECTID IN (18, 26, 20, 22, 35, 38, 148, 149, 155, 278)

  • I'm not sure quite what you're trying to do but the following code should create the the records you want

    INSERT INTO Table1(

    RELATEDRECORDID,

    FIELDID,

    SOURCERECORDID)

    SELECT

    1,

    614,

    ID

    FROM TABLE2 WHERE PROJECTID IN (18, 26, 20, 22, 35, 38, 148, 149, 155, 278)

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • brilliant

    cheers guys

Viewing 4 posts - 1 through 3 (of 3 total)

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