我已经编写了这段代码,以显示单个学生的费用支付,待定等,但实际上它应该适用于整个班级的学生。我尝试了很多,但不能为全班做这件事。这该怎么做 ?忽略@studentID,我只想要@ClassID。
ALTER PROCEDURE [Accounts].[GetUserPaymentsPartialRecord]
@StudentId INT= 14,
@classID int=1
AS
BEGIN
declare @accID int
set @accID= (select st.Account_ID from School.StudentInformation ST where st.StudentID = @StudentId and st.ClassToWhichAdmitted_ID= @classID)
declare @className varchar(50)
Set @className= (Select c.ClassName from School.Classes c
Inner Join School.StudentInformation si
ON si.ClassToWhichAdmitted_ID= c.ClassID where si.StudentID= @StudentId)
declare @transactions varchar(max)
Set @transactions=(select convert(varchar,Convert(decimal(10,0),t.Credit))+', ' AS 'data()' from Accounts.Transactions T
where t.Account_ID = (@accID)
and
t.Credit>0
AND
t.IsReversed=0
AND
t.InvoiceNumber in(Select inv.InvoiceNumber from Accounts.Invoices inv where inv.Student_ID= @StudentId)
AND
Particulars Like '%Received%'
FOR XML PATH(''))
declare @PayableAmount money
set @PayableAmount = (select sum(i.Amount+ i.Fine) from Accounts.Invoices I where I.Student_ID= @StudentId and i.Class_ID = @classID )
declare @TotalAmountPaid money
Set @TotalAmountPaid= (Select sum(t.Credit) from Accounts.Transactions T
where t.Account_ID = (@accID)
and
t.Credit>0
AND
t.IsReversed=0
AND
t.InvoiceNumber in(Select inv.InvoiceNumber from Accounts.Invoices inv where inv.Student_ID= @StudentId)
AND
t.Particulars Like '%Received%'
group by t.Account_ID)
declare @PendingAmount money
Set @PendingAmount= (@PayableAmount - @TotalAmountPaid)
SELECT st.StudentName, st.StudentRegisterationNo,@className as ClassName,
@transactions as Paid, Convert(decimal(10,0),@TotalAmountPaid) as TotalPaid,
@PayableAmount, @PendingAmount as 'PendingAmount' FROM School.StudentInformation ST
where st.StudentID= @StudentId
END
答案 0 :(得分:0)
您可以尝试将上述程序(学生和班级)简单地移动到可以在班级查询的表格集
参见下面的示例程序:
<header></header>
<div class="page-container">
<div class="left-column">left</div>
<div class="center-column">center</div>
<div class="right-column">right</div>
</div>
<footer></footer>