MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DB2 Date and Time Concatenation

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Wed Jan 25, 2012 12:35 pm    Post subject: DB2 Date and Time Concatenation Reply with quote

Hi,
I have a table that have two columns to store date and time. Date column defined as Date data type where as Time column defined as CHAR(4). We would like to alter the table for an additional column with TIMESTAMP data type. The data to the new column should be populated from exisitng date and time columns. Is there any way Can I do using SQL to poulate the data into this column.

Table
COL1 DATE
COL2 CHAR(4)
COL3
--
NEWCOL TIMESTAMP.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Jan 25, 2012 1:51 pm    Post subject: Re: DB2 Date and Time Concatenation Reply with quote

schintala wrote:
Hi,
I have a table that have two columns to store date and time. Date column defined as Date data type where as Time column defined as CHAR(4). We would like to alter the table for an additional column with TIMESTAMP data type. The data to the new column should be populated from exisitng date and time columns. Is there any way Can I do using SQL to poulate the data into this column.

Table
COL1 DATE
COL2 CHAR(4)
COL3
--
NEWCOL TIMESTAMP.


What is the format of time column? Just HHMM ? If you want the new column to have timestamp is it ok to populate the seconds portion with zeroes in time and the micro seconds with zeroes?


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Wed Jan 25, 2012 2:09 pm    Post subject: Reply with quote

Kolusu,
Thank you so much for the reply. Time stored as HHMM in CHAR(4). Yes. We will store the seconds and microseconds are zeros in new column.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Jan 25, 2012 2:14 pm    Post subject: Reply with quote

schintala,

Try this untested sql derived from this post

http://www.mvsforums.com/helpboards/viewtopic.php?t=10528&highlight=timestamp

Code:

UPDATE TABLE
   SET NEWCOL = TIMESTAMP(COL1,TIME(SUBSTR(COL2,1,2)||':'||   
                                    SUBSTR(COL2,3,2)||':00')) 
 ;


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Thu Jan 26, 2012 8:33 am    Post subject: Reply with quote

Thank you so much. It worked.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group