我试图在 SQL Server 2005 中像这样的 select 语句中使用 case 语句,但我收到错误“当 EXISTS 未引入子查询时,只能在选择列表中指定一个表达式。” 不能在 SQL 查询中使用 Case 吗?!
declare @TypeofDayID int
set @TypeofDayID = (Select TypeofDayID from RepInfo where RepInfoID = @RepInfoID)
Select CASE
WHEN @TypeofDayID = 1
THEN (Select * from RepInfo RD inner join SellingInfo S on S.RepInfoID = @RepInfoID)
WHEN @TypeofDayID = 2
THEN (Select * from RepInfo RD inner join UpgradingInfo U on U.RepInfoID = @RepDailyID)
WHEN @TypeofDayID = 9 or @TypeofDayID = 10
THEN (Select * from RepInfo RD inner join DeliveryInfo D on D.RepDailyID = @RepDailyID)
END
from RepInfo RD