I am wondering if there is something like Case where i can wok in SQL for getting multiple columns using 1 case expression in SQL Server 2005. I am a rookie in SQL. Hope it is not too easy and i missed it. Thank you in advance!!
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
You can’t have multiple fields in the THEN part of a case statement. You can just use the same logic to build multiple case statements:
and etc.