Results 1 to 4 of 4

Thread: max

  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Unanswered: 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!

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    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.

  3. #3
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    96

    Re: max

    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

  4. #4
    Join Date
    Feb 2004
    Posts
    2
    Thank You!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •