tags:

views:

23

answers:

1

I've got two fields called T1 and T2 defined as double. I'd like to set T3 with the following conditions:

If T1 & T2 >0 then T3=(T1+T2)/2
If T1==0 then T3=T2
if T2==0 then T3=T1
if T1==0 & T2==0, T3=-9999

I have no idea how to include multiple if statements in the query.

+2  A: 

Use:

UPDATE YOUR_TABLE
   SET t3 = CASE 
              WHEN t1 + t2 > 0 THEN (t1 + t2)/2.0
              WHEN t1 + t2 = 0 THEN -9999
              WHEN t1 = 0 THEN t2
              WHEN t2 = 0 THEN t1
            END

What if t1 + t2 is less than zero?

OMG Ponies
T1 or T2 can never be less than zero (at least not in the data I received). Many thanks OMG Ponies.
Maiasaura