I have a sample table where I have written Case statement.
where I’m not able to write the proper syntax.
SELECT
case
when SECTION = 'A' then
case
WHEN (SECTION ='A' AND ROLE = ROLENUMBER)
THEN 'GOOD'
ELSE 'BAD'
end
else
case
when SECTION <> 'A' and ROLE <> 0 and ROLE is not null and ROLENUMBER <> 0 and ROLENUMBER <> null and ROLENUMBER <> ROLE
then 'GOOD'
else 'BAD'
when SECTION <> 'A' and (ROLE = 0 or ROLE IS null) and ROLENUMBER = ROLE
then 'GOOD'
else 'BAD'
end
FROM
CLASSROOM
Apart from Case Condition is there anyother way to write like IF condition with in the Case condition.
I’m looking to write query like IF section = 'A' then execute 1st condition ELSE IF section <> 'A'then execute below condition
.
2
Answers
Does this capture all your "good" conditions?
You can write it more simpler like this.