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 

Can we update columns of a table partially

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


Joined: 24 Aug 2005
Posts: 32
Topics: 14
Location: Hyderabad

PostPosted: Mon May 08, 2006 10:47 am    Post subject: Can we update columns of a table partially Reply with quote

Hi All,

I got a situation where I need to update the month and year part of a column which is defined as DATE, leaving the days part alone.
Is this possible???
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon May 08, 2006 11:07 am    Post subject: Reply with quote

sharada,

Assuming that your table has a column named Date_col which needs to be updated. It stores the date in the format CCYY-MM-DD, the following sql will update the date to 2005-01-dd for all the rows of the table.

Code:

UPDATE TABLE                                 
   SET DATE_COL = CHAR('2005-') CONCAT     
                  CHAR('01-')   CONCAT     
                  SUBSTR(CHAR(DATE_COL),9,2)
                 ;                         


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon May 08, 2006 11:34 am    Post subject: Reply with quote

Kolusu,
I did not test...but, do we really need the CHAR function...?
_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon May 08, 2006 11:48 am    Post subject: Reply with quote

Quote:

I did not test...but, do we really need the CHAR function...?


Cogito-Ergo-Sum,

which Char function are you you concerned ? is it for the constants or CHAR on the date column?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon May 08, 2006 11:24 pm    Post subject: Reply with quote

Constants.

When I ran
Code:
SELECT CHAR('TEST DATA') FROM SYSIBM.SYSDUMMY1 ;
, I see CHAR(9) column definition in SYSPUNCH. But, when I use
Code:
SELECT 'TEST DATA' FROM SYSIBM.SYSDUMMY1 ;
, I see VARCHAR column definition in SYSPUNCH.

Could this be the reason, why you used the CHAR function ?
_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue May 09, 2006 8:23 am    Post subject: Reply with quote

Cogito-Ergo-Sum,


A Column defined as Date actually stores the data in Character format. And as you have noticed a constant supplied within Quotes is treated as a Varchar data and Db2 add 2 extra bytes for the length. So it is necessary to use the CHAR function so that we don't have the extra 2 bytes.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
srini_igsi
Beginner


Joined: 12 May 2006
Posts: 41
Topics: 16
Location: Mumbai

PostPosted: Fri May 12, 2006 4:58 am    Post subject: Reply with quote

Hi Colusu,

Here what is 'CONCAT' and whats its role? Is this a DB2 Keyword?
_________________
Thanks,
-Srini
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri May 12, 2006 7:32 am    Post subject: Reply with quote

srini_igsi,

Srini,

Concat function combines two string arguments. It is a function in almost all the relation databases.

Check this link for a detailed explanation of the function concat

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/3.2.14?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu

Ps: I would really appreciate if you can spell my name correctly
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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