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 > Updating the values with date YYYYMMDD

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-09, 00:15
laknar laknar is offline
Registered User
 
Join Date: Jul 2008
Posts: 80
Updating the values with date YYYYMMDD

I have the below values in a column called COLUMN1

DS_AC_SS_20080122
DS_CS_SS_20080122
DS_CR_SS_20080122
DS_AS_SS_20080122
DS_TN_SS_20080122
DS_BS_SS_20080122
DS_CU_SS_20080122

how to update the above values into below by using single update statement

DS_AC_SS_20080123
DS_CS_SS_20080123
DS_CR_SS_20080123
DS_AS_SS_20080123
DS_TN_SS_20080123
DS_BS_SS_20080123
DS_CU_SS_20080123

Note: 20080123 is YYYYMMDD when ever i update the column should update with +1 day
Reply With Quote
  #2 (permalink)  
Old 03-30-09, 01:01
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
There will be many ways.

Here is an example.
Code:
UPDATE .....
   SET column1
     = SUBSTR(column1, 1, 9)
       || TRANSLATE( 'abcdefgh'
                   , CHAR( DATE( TRANSLATE( 'abcd-ef-gh'
                                          , SUBSTR(column1, 10, 8) 
                                          , 'abcdefgh')
                               ) + 1 DAY
                         , ISO)
                   , 'abcd-ef-gh')
.....
;
Reply With Quote
  #3 (permalink)  
Old 03-30-09, 01:39
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If you are using DB2 V9.5, you can use TO_CHAR and TO_DATE.
Code:
   SET column1
     = SUBSTR(column1, 1, 9)
       || TO_CHAR(TO_DATE(SUBSTR(column1, 10, 8), 'YYYYMMDD') + 1 DAY, 'YYYYMMDD')
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