In C#, I frequently use the defensive technique of throwing an exception if I get to the default case of a switch statement. In t-sql (specifically SQL Server 2005), there is a similar construct called CASE.
I would like to be able to use the same technique in t-sql, e.g.
SELECT (
CASE
WHEN Blah IN ('A', 'B') THEN 3
WHEN Blah IN ('C', 'D') THEN 2
ELSE raiserror('unhandled blah type', 16, 1)
END) As Halb
However, t-sql gives the error:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'raiserror'.
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near ')'.
Is there any way to accomplish this type of scenario or is there another, more common, t-sql approach to this pattern?