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 > How to create a column who value is derived from two other columns ??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 09:36
ranjir75 ranjir75 is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 13
How to create a column who value is derived from two other columns ??

If there are two columns in table, named column A and column B, Can we add one more column C to the table which would always have sum of A and B. If value of A or B is changed, the value of A + B should automaticaly get reflected in varlable C.

Please, let me know what are the ways in which this can be accomplished in DB2.
__________________
Thanks
Ranjith
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 09:43
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Re: How to create a column who value is derived from two other columns ??

Quote:
Originally posted by ranjir75
If there are two columns in table, named column A and column B, Can we add one more column C to the table which would always have sum of A and B. If value of A or B is changed, the value of A + B should automaticaly get reflected in varlable C.

Please, let me know what are the ways in which this can be accomplished in DB2.
Triggers.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 10:49
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You can also use:

ALTER TABLE TableA add column COL_C INTEGER generated always as (COL_A + COL_B).

Andy
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