我想用这个代码在 cte 中用例:
Declare @DefinitionType Int = 1
;With Res
As
(
Case @DefinitionType
When 1 Then (Select [ActionId], [Title] From Actions)
When 2 Then (Select [AreaId], [Title] From Areas)
Else (Select [ContractorScopeId], [Title] From ContractorScopes)
End
)
Select * From Res
该错误是:
消息 156,级别 15,状态 1,第 5 行
关键字“案例”附近的语法不正确。
如何在 CTE 中使用案例陈述?