If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to add timestamp column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-10, 04:05
saching saching is offline
Registered User
 
Join Date: Dec 2009
Posts: 15
How to add timestamp column

Hi,

using DB V9.5

How to add two timestamp column through sql query.
Reply With Quote
  #2 (permalink)  
Old 04-26-10, 04:16
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
alter table table-name add column column-name timestamp;

A reorg is optional, but recommended, especially if you plan on updating the column for existing rows.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 04-26-10, 06:19
saching saching is offline
Registered User
 
Join Date: Dec 2009
Posts: 15
Thanks for u'r response,

not add columns in table .

my question is How to sum both the column that have timestamp datatype

ie.

1. select (timestamp1_col) + (timestamp2_col) from test ;

2. select sum (timestamp1_col + timestamp2_col) from test;

while exceute this command ,getting the error the following error

SQL0402N The data type of an operand of an arithmetic function or operation
"+" is not numeric. SQLSTATE=42819

SQL0402N The data type of an operand of an arithmetic function or operation "+ " is not numeric.
Reply With Quote
  #4 (permalink)  
Old 04-26-10, 06:36
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
What result(data type and value) do you expect by adding timestamp columns?

For example:
TIMESTAMP('2010-04-27-09.13.56.234') + TIMESTAMP('2010-04-28-14.22.19.789') = ??????(what are your expected data type and value?)
Reply With Quote
  #5 (permalink)  
Old 04-26-10, 06:45
saching saching is offline
Registered User
 
Join Date: Dec 2009
Posts: 15
thanks again

Expacting Integer datatype and value should in minute
Reply With Quote
  #6 (permalink)  
Old 04-26-10, 07:12
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
Expacting Integer datatype and value should in minute
TIMESTAMP('2010-04-27-09.13.56.234') + TIMESTAMP('2010-04-28-14.22.19.789') = xxxx minutes?
Reply With Quote
  #7 (permalink)  
Old 04-26-10, 08:06
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
saching,

If you gave your answer to the following expression(hopefully with the way to calculate the answer),
Quote:
TIMESTAMP('2010-04-27-09.13.56.234') + TIMESTAMP('2010-04-28-14.22.19.789') = xxxx minutes?
I will try to give you DB2 SQL expression(and/or UDF) to produce the answer.
Reply With Quote
  #8 (permalink)  
Old 04-26-10, 11:21
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Exclamation Minus, only

Quote:
Originally Posted by saching View Post
Thanks for u'r response,

not add columns in table .

my question is How to sum both the column that have timestamp datatype

ie.

1. select (timestamp1_col) + (timestamp2_col) from test ;

2. select sum (timestamp1_col + timestamp2_col) from test;

while exceute this command ,getting the error the following error

SQL0402N The data type of an operand of an arithmetic function or operation
"+" is not numeric. SQLSTATE=42819

SQL0402N The data type of an operand of an arithmetic function or operation "+ " is not numeric.
You can use only one arithmetic operation between two timestamps: "-".


Lenny
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On