我想要做一些类似这样的事情。
declare @a int=1
if (@a=1)
with cte as
(
select UserEmail from UserTable
)
else
with cte as
(
select UserID from UserTable
)
select * from cte
这只是一个例子,我的实际查询要复杂得多。因此,我不想在CTE之后两次写IF
和ELSE
语句中的SELECT
语句。
if
的替代方法最终会产生两个具有重复内容的查询。 - Damien_The_Unbeliever