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 > max

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-04, 10:53
miii miii is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
max

Hi
A table with fields A, B, C and D. I have to perform the following calculation:
D=A- max(B,C)
I have to substract B or C from A.
How to set the calculated formula?
Or how to calculate it with a trigger?

Thank you in advance!
Reply With Quote
  #2 (permalink)  
Old 02-02-04, 11:06
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: max

AFAIK, there is no max function to comapre different columns in the same row ..

But, I assume you should be able to write a SQL UDF very easily

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 02-02-04, 13:28
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Re: max

Quote:
Originally posted by miii
Hi
A table with fields A, B, C and D. I have to perform the following calculation:
D=A- max(B,C)
I have to substract B or C from A.
How to set the calculated formula?
Or how to calculate it with a trigger?

Thank you in advance!
You can use the case statement, assuming you're using DB2 Windows/Unix (don't know about DB2/OS390)

Also assuming that A is the key column this should work:

Code:
update t1 x set d = 

     (select 
                case
                   when b>c then a-b
                else
                   a-c
                end

         from t1 y
       where x.a = y.a )
          ;

Kind regards, Gert
Reply With Quote
  #4 (permalink)  
Old 02-03-04, 02:43
miii miii is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Thank You!
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