Previous Topic

Next Topic

Inhoudsopgave

Book Index

Case Statements And Nesting

MS SQL Server allows a maximum of 10 nested case statements. ASE does not have a limit.

Example of 2 nesting levels

declare @Char char(1)

set @Char = 'z'

select

case

when @Char = 'a' then '1'

else case

when @Char = 'b' then '2'

else case

when @Char = 'c' then '3'

else '?'

end

end

end

end

Remark

Most of the time, you do not need nesting of case statements. The expressions used in the ‘When’ clauses can be as complex as you like. Furthermore, you can add as many ‘When’ clauses as you need.

declare @Char char(1)

set @Char = 'z'

select

case

when @Char = 'a' then '1'

when @Char = 'b' then '2'

when @Char = 'c' then '3'

else '?'

end