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 > AS400 (DB2) Date Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-10, 14:57
Michael00 Michael00 is offline
Registered User
 
Join Date: Jun 2010
Posts: 1
AS400 (DB2) Date Function

I need function or code to take two fields one is the Century the other is the rest of the date. Example: RCRCCC = 20 RCRCDT = 100610

What I am try to do is create a view that takes the two fields puts them together into another field that is date format (2010-06-10 00:00:00.000)

Here it is in SQL:
CASE WHEN len(PODET.PDLRDT) = 6 THEN CAST(CAST(PODET.PDLRCC AS varchar(10)) + CAST(PODET.PDLRDT AS varchar(10)) AS datetime)
WHEN PODET.PDLRCC = 0 OR PODET.PDLRDT = 0 THEN NULL
WHEN PODET.PDLRCC = 20 AND len(PODET.PDLRDT) = 4 THEN CAST(CAST(PODET.PDLRCC AS varchar(10)) + '00' + CAST(PODET.PDLRDT AS varchar(10)) AS datetime)
WHEN PODET.PDLRCC = 20 AND len(PODET.PDLRDT) = 3 THEN CAST(CAST(PODET.PDLRCC AS varchar(10)) + '000' + CAST(PODET.PDLRDT AS varchar(10)) AS datetime)
WHEN PODET.PDLRCC = 19 THEN CAST(CAST(PODET.PDLRCC AS varchar(10)) + CAST(PODET.PDLRDT AS varchar(10)) AS datetime)
WHEN PODET.PDLRCC = 20 THEN CAST(CAST(PODET.PDLRCC AS varchar(10)) + '0' + CAST(PODET.PDLRDT AS varchar(10)) AS datetime) ELSE NULL
END as NEW_DATE_FIELD


HERE IS TABLE/View Fields
RCRCDT, RCRCCC,
PODET.PDITNO,
POHED.PHPONO,
PODET.PDWHID,
PODET.PDQRCD,
PODET.PDUNMS,
PODET.PDPDS1,
PODET.PDPDS2,
PODET.PDVNNO
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