I trying to use a Case Statement in the Where Clause and I'm having difficulties.
The Where Clause has three conditions. Condition1 AND either Condition2 or Condtion3 must be met. I use @Variable1 to determine whether Condition2 or Condition3 must be met. When @Variable1 = "Operations" then Condition2 applies when @Variable1 = "Admin" then Condition3 applies:
- Condition1 Field1 = 'Regional'
- Condition2 When @Variable1 = "Operations": Field2 = 'Seattle' AND Field3 = "Primary'
- Condition3 When @Variable1 = "Admin": Field4 = 'Portland'
Thanks for you help.
....bob sutor
My Code:
WHERE
Field1 = 'Regional'
AND ((CASE Varible1 WHEN 'Operations' THEN Field2 END = 'Seattle'
AND CASE Varible1 WHEN 'Operations' THEN Field3 END = 'Primary')
OR CASE Varible1 WHEN 'Admin' THEN Field4 END = 'Portland')
Bob Sutor