By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

Insert to table question

P: 5
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.....
Expand|Select|Wrap|Line Numbers
  1. 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,
Expand|Select|Wrap|Line Numbers
  1. Column                         Type      Type
  2. name                           schema    name               Length   Scale Nulls
  3. ------------------------------ --------- ------------------ -------- ----- ------
  4. SYSTEM_DATE                    SYSIBM    TIMESTAMP                10     0 No
  5. ID                               SYSIBM    DECIMAL                   6     0 Yes
  6. TYPE                             SYSIBM    VARCHAR                  25     0 Yes
  7. RECORDS                        SYSIBM    DECIMAL                   8     0 Yes
  8. COUNTRY                        SYSIBM    VARCHAR                   2     0 Yes
Thanks in advance
Mar 10 '08 #1
Share this Question
Share on Google+
1 Reply


sakumar9
Expert 100+
P: 127
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.....
Expand|Select|Wrap|Line Numbers
  1. 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,
Expand|Select|Wrap|Line Numbers
  1. Column                         Type      Type
  2. name                           schema    name               Length   Scale Nulls
  3. ------------------------------ --------- ------------------ -------- ----- ------
  4. SYSTEM_DATE                    SYSIBM    TIMESTAMP                10     0 No
  5. ID                               SYSIBM    DECIMAL                   6     0 Yes
  6. TYPE                             SYSIBM    VARCHAR                  25     0 Yes
  7. RECORDS                        SYSIBM    DECIMAL                   8     0 Yes
  8. COUNTRY                        SYSIBM    VARCHAR                   2     0 Yes
Thanks in advance

You can try this command:

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO table1 (SYSTEM_DATE, id, type, records, country) 
  3.            select CURRENT TIMESTAMP, id, type, count(*), country  from                                      
  4.                tdb.table2 where id = 222 
  5.                and group by id, type
  6.  
  7.  
Regards
-- Sanjay
Mar 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.