473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Coverting decimal field to db2 date?

Ron
Who knows how to convert a field with picture
decimal (8) to a db2 date?

--
Met vriendelijke groet
Ron van der Poel
Nov 12 '05 #1
5 2306
"Ron" <fa*******@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...
Who knows how to convert a field with picture
decimal (8) to a db2 date?

--
Met vriendelijke groet
Ron van der Poel

If you have a host variable with PIC 9(8), and the format is YYYYMMDD (or
similar), and you want to use that host variable in an SQL statement, then
here is one way.

First, make sure the it is not defined as S9(8). If it is, move it to a
variable that is defined as PIC 9(8) to strip off the sign. The PIC 9(8)
target variable should be REDEFINED as PIC X(8), with separate subordinate
levels for the year, month, and day as individual variables X(4), X(2), and
X(2).

Then move the character year, month, and day variables to another variable
which has embedded dashes so that the final character filed is defined as
PIC X(10) as follows '2005-04-13'.

Then use the PIC X(10) variable as a host variable in the SQL statement.
Nov 12 '05 #2
Ron
it has to be done in one statement, so I have to use db2-functions
we're not dealing with host variables or cobol programming

--
Met vriendelijke groet
Ron van der Poel
"Mark A" <no****@nowhere.com> schreef in bericht
news:9P********************@comcast.com...
"Ron" <fa*******@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...
Who knows how to convert a field with picture
decimal (8) to a db2 date?

--
Met vriendelijke groet
Ron van der Poel
If you have a host variable with PIC 9(8), and the format is YYYYMMDD (or
similar), and you want to use that host variable in an SQL statement, then
here is one way.

First, make sure the it is not defined as S9(8). If it is, move it to a
variable that is defined as PIC 9(8) to strip off the sign. The PIC 9(8)
target variable should be REDEFINED as PIC X(8), with separate subordinate
levels for the year, month, and day as individual variables X(4), X(2),

and X(2).

Then move the character year, month, and day variables to another variable
which has embedded dashes so that the final character filed is defined as
PIC X(10) as follows '2005-04-13'.

Then use the PIC X(10) variable as a host variable in the SQL statement.

Nov 12 '05 #3
Ron wrote:
it has to be done in one statement, so I have to use db2-functions
we're not dealing with host variables or cobol programming

--
Met vriendelijke groet
Ron van der Poel
"Mark A" <no****@nowhere.com> schreef in bericht
news:9P********************@comcast.com...
"Ron" <fa*******@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl.. .
Who knows how to convert a field with picture
decimal (8) to a db2 date?

--
Met vriendelijke groet
Ron van der Poel


If you have a host variable with PIC 9(8), and the format is YYYYMMDD (or
similar), and you want to use that host variable in an SQL statement, then
here is one way.

First, make sure the it is not defined as S9(8). If it is, move it to a
variable that is defined as PIC 9(8) to strip off the sign. The PIC 9(8)
target variable should be REDEFINED as PIC X(8), with separate subordinate
levels for the year, month, and day as individual variables X(4), X(2),


and
X(2).

Then move the character year, month, and day variables to another variable
which has embedded dashes so that the final character filed is defined as
PIC X(10) as follows '2005-04-13'.

Then use the PIC X(10) variable as a host variable in the SQL statement.

CREATE FUNCTION DEC8_2_DATE(arg DECIMAL(8, 0)) RETURNS DATE
CONTAINS SQL DETERMINISTIC NO EXTERNAL ACTION
RETURN (SELECT DATE(SUBSTR(numstr, 1, 4)
|| '-'
|| SUBSTR(numstr, 5, 2)
|| '-'
|| SUBSTR(numstr, 7, 2))
FROM TABLE(VALUES (CHAR(arg)))AS T(numstr));

VALUES DEC8_2_DATE(20050412);
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
"Ron" <fa*******@wanadoo.nl> wrote in message
news:42***********************@news.wanadoo.nl...
it has to be done in one statement, so I have to use db2-functions
we're not dealing with host variables or cobol programming

If you are not dealing with COBOL, where did you get the term "picture". Is
it used in any other programming language?
Nov 12 '05 #5
Another idea:

CREATE FUNCTION DEC8_2_DATE(arg DECIMAL(8, 0))
RETURNS DATE
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN DATE(TIMESTAMP(DIGITS(arg)||'000000'));

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Kennedy | last post by:
I am pulling a decimal value from SQL server and trying to use the format currency and format number function. I am using these values in a large string of HTML to be used in a CDONTS Email. If I...
2
by: wireless | last post by:
In our database is a decimal field with format YYMMDDhhmmss.9999999999 where the 9s are random digits. I'm trying to strip off just the YYMMDD and put it in date form. So far I came up with:...
0
by: Casey | last post by:
Hi! I found several resources describing how to convert the UNIX timestamp to a readable date, however I need to convert a date into a UNIX timestamp. For instance, I'm writing a program that will...
0
by: John D. | last post by:
I am having problems inserting Decimal values into a DB2 database via a .NET/C# application which is using an OdbcDataAdapter. Other field types such as VarChar, Int, Date, etc work ok, and I can...
3
by: vp | last post by:
Hi all, I have a field AMOUNT(Decimal 13,2) and when I check the length its coming as 7. AMOUNT LENGTH 15.00 7 118.00 7 0.00 7 10.00 7
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
8
by: Tony B | last post by:
I have a string in a existing php script which is in the form "dd/mm/yyyy" and I need to convert it into a suitable format for mysql which is "yyyy-mm-dd" Is there a neat way of doing this in php ?
9
by: Frank Swarbrick | last post by:
I've probably asked this before, but I can't remember the answer! One can use the DECIMAL function to convert a date to a decimal. For instance values decimal(current_date) returns 20080528. ...
3
by: Celal | last post by:
Hi, I couldn't get around a problem about decimal rounding up when adding a record to a table from a form by programming a button. I have an invoice form where the grand total is a calculated text...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.