Conditional SQL SELECT
Posted on 2011-05-08
I am adding a column to table TBL1. Each row of TBL1 will have a new value, no gaps and no extra rows.
I need to create the new column with each row holding its value as either;
IF( TBL2.bool_field1 ) THEN TBL3.A+TBL1.T
IF( TBL2.bool_field2 ) THEN TBL3.B+TBL1.T
IF( TBL2.bool_field3 ) THEN TBL3.C+TBL1.T
TBL2 and TBL3 rows are indexed by FK2, FK3 held within TBL1.
(There are three boolean field. I may be able to change those fields to a single field with one of three values but would rather not)
I cannot quite get the SELECT .. CASE statement to do this.
I am looking for a simple single statement SQL statement.
The statement should include the condition above plus a token column from another table.