ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Insert all columns into new table, plus several additional columns

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Insert all columns into new table, plus several additional columns

    I have two tables (Table A and Table B) that are "near" mirror images of each other. Table B has 4 additional columns at the end of the table. The other field names are even the same (Table B is an audit file of Table A that contains additional columns for transaction code, user, date, and time).

    In RPG, I simply read Table A, update 4 fields, then write Table B.

    What is the syntax for:
    INSERT into B
    SELECT * FROM TABLE A WHERE field1=x and field2=y;

    Can I?
    If so, where do I put the values for the additional 4 columns?

    Thx

  • #2
    Nevermind... I figured it out using trial and error.

    INSERT into B
    SELECT a.*, data1, data2, data3, data4 FROM TABLE A as a WHERE field1=x and field2=y;

    Comment

    Working...
    X