Insert to table question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spanky1968
    New Member
    • Sep 2007
    • 5

    Insert to table question

    Hello,

    I have a small dilemma I need some help with. I would like to insert into a DB2 table the system date (timestamp) along with data retrieved via a db2 select statement but I am unsure how to code it using one statement.

    I would like to use the following format to insert to the table but I am unsure how to add the "VALUES (CURRENT TIMESTAMP)"

    Format I would like to use.....
    Code:
    db2 "INSERT INTO table1 (id, type, records, country) select id, type, count(*), country  from tdb.table2 where id = 222 and group by id, type"
    Also here is the table stucture,
    Code:
    Column                         Type      Type
    name                           schema    name               Length   Scale Nulls
    ------------------------------ --------- ------------------ -------- ----- ------
    SYSTEM_DATE                    SYSIBM    TIMESTAMP                10     0 No
    ID           		            SYSIBM    DECIMAL                   6     0 Yes
    TYPE                  	       SYSIBM    VARCHAR                  25     0 Yes
    RECORDS                        SYSIBM    DECIMAL                   8     0 Yes
    COUNTRY                        SYSIBM    VARCHAR                   2     0 Yes
    Thanks in advance
  • sakumar9
    Recognized Expert New Member
    • Jan 2008
    • 127

    #2
    Originally posted by spanky1968
    Hello,

    I have a small dilemma I need some help with. I would like to insert into a DB2 table the system date (timestamp) along with data retrieved via a db2 select statement but I am unsure how to code it using one statement.

    I would like to use the following format to insert to the table but I am unsure how to add the "VALUES (CURRENT TIMESTAMP)"

    Format I would like to use.....
    Code:
    db2 "INSERT INTO table1 (id, type, records, country) select id, type, count(*), country  from tdb.table2 where id = 222 and group by id, type"
    Also here is the table stucture,
    Code:
    Column                         Type      Type
    name                           schema    name               Length   Scale Nulls
    ------------------------------ --------- ------------------ -------- ----- ------
    SYSTEM_DATE                    SYSIBM    TIMESTAMP                10     0 No
    ID           		            SYSIBM    DECIMAL                   6     0 Yes
    TYPE                  	       SYSIBM    VARCHAR                  25     0 Yes
    RECORDS                        SYSIBM    DECIMAL                   8     0 Yes
    COUNTRY                        SYSIBM    VARCHAR                   2     0 Yes
    Thanks in advance

    You can try this command:

    Code:
    INSERT INTO table1 (SYSTEM_DATE, id, type, records, country) 
               select CURRENT TIMESTAMP, id, type, count(*), country  from                                      
                   tdb.table2 where id = 222 
                   and group by id, type
    Regards
    -- Sanjay

    Comment

    Working...