create Procedure ap_Terms_List
-- return list of due days for the leasing
@dtsStartDate smalldatetime,
@dtsEndDate smalldatetime,
@chvLeaseFrequency varchar(20)
As
set nocount on
declare @insDueDates smallint -- number of intervals
-- calculate number of DueDates
select @insDueDates =
Case @chvLeaseFrequency
When 'monthly'
then DateDiff(month, @dtsStartDate, @dtsEndDate)
When 'semi-monthly'
then 2 * DateDiff(month, @dtsStartDate, @dtsEndDate)
When 'bi-weekly'
then DateDiff(week, @dtsStartDate, @dtsEndDate)/2
When 'weekly'
then DateDiff(week, @dtsStartDate, @dtsEndDate)
When 'quarterly'
then DateDiff(qq, @dtsStartDate, @dtsEndDate)
When 'yearly'
then DateDiff(y, @dtsStartDate, @dtsEndDate)
END
-- generate list of due dates using temporary table
Create table #DueDates (ID int)
while @insDueDates >= 0
begin
insert #DueDates (ID)
values (@insDueDates)
select @insDueDates = @insDueDates - 1
end
-- display list of Due dates
select ID+1, Convert(varchar,
Case
When @chvLeaseFrequency = 'monthly'
then DateAdd(month, ID, @dtsStartDate)
When @chvLeaseFrequency = 'semi-monthly'
and ID/2 = CAST(ID as float)/2
then DateAdd(month, ID/2, @dtsStartDate)
When @chvLeaseFrequency = 'semi-monthly'
and ID/2 <> CAST(ID as float)/2
then DateAdd(dd, 15,
DateAdd(month, ID/2, @dtsStartDate))
When @chvLeaseFrequency = 'bi-weekly'
then DateAdd(week, ID*2, @dtsStartDate)
When @chvLeaseFrequency = 'weekly'
then DateAdd(week, ID, @dtsStartDate)
When @chvLeaseFrequency = 'quarterly'
then DateAdd(qq, ID, @dtsStartDate)
When @chvLeaseFrequency = 'yearly'
then DateAdd(y, ID, @dtsStartDate)
END , 105) [Due date]
from #DueDates
order by ID
-- wash the dishes
drop table #DueDates
return
0 comments:
Post a Comment
plzz give the comment