Skip to content

Instantly share code, notes, and snippets.

@BalajiIyengar
Last active August 29, 2015 14:02
Show Gist options
  • Save BalajiIyengar/af98f036347773ebc16d to your computer and use it in GitHub Desktop.
Save BalajiIyengar/af98f036347773ebc16d to your computer and use it in GitHub Desktop.
Create Stored Procedures
Create procedure sp_createInstallment
(
@studentId int,
@installmentNo int,
@monthlyPattern int,
@preferredDate date,
@perferredAmount money
)
AS
Begin
Declare
@feeAmount money,
@remainingAmount money
set @feeAmount=(select F.Amount from tblStudentDetails S inner join tblFeesMaster F on S.CourseId=F.CourseId
where S.StudentId=@studentId and S.isActive=1 and F.isActive=1)
while(@installmentNo!=0)
Begin
set @remainingAmount=@feeAmount-@perferredAmount
insert into tblfeeStructure(StudentID,InstallmentNo,InstallmentAmount,InstallmentDate,AmountRemaining,CreatedDate) values(@studentId,@installmentNo,@perferredAmount,DATEADD(MONTH,1,@preferredDate),@remainingAmount,GETDATE())
set @installmentNo=@installmentNo-1
set @feeAmount=@feeAmount-@perferredAmount
set @preferredDate=DATEADD(MONTH,1,@preferredDate)
End
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment