我想知道是否有类似案例的东西,我可以在 SQL 中使用 SQL Server 2005 中的 1 个案例表达式来获取多列。我是 SQL 的新手。希望这不是太容易,我错过了。先感谢您!!
Select RD.RepDailyInfoID, RD.TypeofDayID
Case WHEN RD.TypeofDayID = 1
THEN
isnull(cast(S.AmountSold as numeric(10,2)), 0) as AmountSold,
isnull(cast(S.S_AmountCollected as numeric(10,2)), 0) as AmountCollected,
S.S_PaymentMethod as PaymentMethod
When RD.TypeofDayID = 9
THEN
isnull(cast(U.AmountUpgraded as numeric(10,2)), 0) as AmountUpgraded,
isnull(cast(U.U_UpgradedCollected as numeric(10,2)), 0) + isnull(cast(U.RenewalCollected as numeric(10,2)), 0) as AmountCollected,
U.U_PaymentMethod as PaymentMethod
END
from RepDailyInfo RD
left outer join SellingInfo S on S.RepDailyInfoID = RD.RepDailyInfoID
left outer join UpgradingInfo U on U.RepDailyInfoID = RD.RepDailyInfoID
where RepID = @RepID