| |
|
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.
|
 |

11-05-09, 06:35
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 2
|
|
DB2, editing Timestamp(char) to (integer)
|
|
Hi,
I am currently working with DB2 9.1, but my timestamps is in char after running my query, this makes it difficult to interpret this report and I try editing the coloum which I found difficult as well.
I am working on Window server 2003 EE, and I am trying to generate report for ITM using BIRT Bussiness Intelligent reporting tools v2.2.2, my database connection with BIRT was successful but the date of the report is an issue to explain.
Please help me.
Thank u.
|
Last edited by Yetunde; 11-05-09 at 06:48.
|

11-05-09, 07:15
|
|
Registered User
|
|
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
|
|
try to remove the characters (: . )with translate and convert to integer
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
|
|

11-13-09, 11:15
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 2
|
|
|
|
I have tried all possible best to remove the character to integer but it seems not working, It gives no room for edition.
|
|

11-13-09, 11:27
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
|
|
first that comes to mind is:
c1 with value let's say '2002-12-25-17.12.30.123456'
integer(substr(c1,1,4)||substr(c1,6,2)||substr(c1, 9,2)||substr(c1,12,2)... )
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
|
Last edited by MarkhamDBA; 11-13-09 at 11:31.
|

11-13-09, 11:51
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 886
|
|
Decimal(18,0)
Quote:
Originally Posted by MarkhamDBA
first that comes to mind is:
c1 with value let's say '2002-12-25-17.12.30.123456'
integer(substr(c1,1,4)||substr(c1,6,2)||substr(c1, 9,2)||substr(c1,12,2)... )
|
Integers have a limit +2147483647.... After this you will get arithmetic exception error.
Better, instead of integer, using DECIMAL(18,0)....
Lenny
|
|

11-13-09, 12:05
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
Yetunde,
what format do you want from timestamp 'yyyy-mm-dd-hh.mi.ss.ssssss'?
|
|

11-13-09, 12:22
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
|
|
Quote:
Originally Posted by Lenny77
Integers have a limit +2147483647.... After this you will get arithmetic exception error.
Better, instead of integer, using DECIMAL(18,0)....
Lenny
|
you are right. actually DECIMAL function can be used to convert timestamp to decimal data type. Excerpt from DB2 SQL documentation:
function with arguments = DECIMAL(2000-03-21-12.02.21.123456, 23)
precision and scale = (23, 6)
result = 20000321120221.123456
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
|
|

11-13-09, 12:34
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 886
|
|
decimal(..., 23) ...instruction to use...
Quote:
Originally Posted by MarkhamDBA
you are right. actually DECIMAL function can be used to convert timestamp to decimal data type. Excerpt from DB2 SQL documentation:
function with arguments = DECIMAL(2000-03-21-12.02.21.123456, 23)
precision and scale = (23, 6)
result = 20000321120221.123456
|
Actually:
Code:
select decimal(replace(
translate(varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
|
|

11-13-09, 13:30
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
|
|
Quote:
Originally Posted by Lenny77
Actually:
Code:
select decimal(replace(
translate(varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
|
Lenny, why do you need replace/translate/varchar here? argument of DECIMAL function can be of timestamp type. I tested it and it works 
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
|
Last edited by MarkhamDBA; 11-13-09 at 13:39.
|

11-13-09, 14:24
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 886
|
|
Like integer
Quote:
Originally Posted by MarkhamDBA
Lenny, why do you need replace/translate/varchar here? argument of DECIMAL function can be of timestamp type. I tested it and it works 
|
Because I don't want to have a fraction....
Code:
select current timestamp,
decimal(replace(translate(
varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Now you can operate with result in same way how you are working with integers....
Code:
select
decimal(replace(translate(
varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
-
decimal(replace(translate(
varchar(current timestamp - 111 minute), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|