我有一個t-sql表列出了多個位置的協議。TSQL組按列
色譜柱:
- STID =商店ID
- AStatID =協議狀態ID(1 =活動)
- PayModeID =(1每日=,2 =每週,等等。)
- 然後每個的PayMode的列達
我試圖讓我們每月潛在來自活躍協議,每家商店的收入。
這是我到目前爲止,但我得到的錯誤「子查詢返回多個值1」。
我哪裏錯了?
SET NOCOUNT ON
Declare @dPotential Money,
@wPotential Money,
@bPotential Money,
@sPotential Money,
@mPotential Money,
@Potential Money;
Set @dPotential = (((Select Agreemnt.DailyRate FROM Agreemnt WHERE Agreemnt.PayModeID = 1 And Agreemnt.AStatID = 1)*365)/12)
Set @wPotential = (((Select Agreemnt.WeeklyRate FROM Agreemnt WHERE Agreemnt.PayModeID = 2 And Agreemnt.AStatID = 1)*52)/12)
Set @bPotential = (((Select Agreemnt.WeeklyRate FROM Agreemnt WHERE Agreemnt.PayModeID = 3 And Agreemnt.AStatID = 1)*52)/12)
Set @sPotential = (((Select Agreemnt.DailyRate FROM Agreemnt WHERE Agreemnt.PayModeID = 4 And Agreemnt.AStatID = 1)*24)/12)
Set @mPotential = ((Select Agreemnt.DailyRate FROM Agreemnt WHERE Agreemnt.PayModeID = 5 And Agreemnt.AStatID = 1)* 12)
Set @Potential = @dPotential + @wPotential + @bPotential + @sPotential + @mPotential
Select Agreemnt.STID, @Potential From Agreemnt
Group By Agreemnt.STID
這些查詢到您的變量分配值來返回多行多 – Lamak