我想知道是否有類似的情況下,我可以在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
只需將您的案例邏輯複製+粘貼到每列 – EplusL