0

I'd like to select a value from COL_B as COL_A based on conditions in COL C,D & E. I am trying to avoid using an update query. Similar to a nested IF in Excel.

IF COL_C=TRUE AND COL_D=TRUE AND COL_E=TRUE
THEN SELECT COL_B AS COL_A
ELSE COL_A

I could just shove it into a temp table and update COL_A to COL_B based on the conditions, but I'd like to do it on the SELECT statement. Any ideas?

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

0

Something like the following may be what you need:

SELECT my_result =
  CASE
    WHEN COL_C=TRUE AND COL_D=TRUE and COL_E=TRUE THEN COL_B
    ELSE COL_A
  END
 AS COL_A
 FROM my_table

Also see this question

Community
  • 1
  • 1
duncan
  • 2,323
  • 3
  • 17
  • 21
0

Thanks. That worked.

[Result]= CASE WHEN COL_A=TRUE AND COL_B=TRUE AND COL_C=TRUE THEN COL_D ELSE COL_E END