[dbo].[GetVanLineStatementPeriodEndDate]
CREATE FUNCTION [dbo].[GetVanLineStatementPeriodEndDate](
@inVanlineGroupExternalCode varchar(10),
@inStatementYear int,
@inStatementNumber int,
@inDefaultEndDate datetime )
returns datetime as
begin
declare @outStatementEndDate datetime
declare @theMonth int
declare @theDay int
declare @theYear int
if( @inVanlineGroupExternalCode = 'SIRVA' )
begin
if( @inStatementYear >= 2000 and @inStatementYear <= 9999 and @inStatementNumber >= 1 and @inStatementNumber <= 24 )
begin
select
@theYear = @inStatementYear,
@theMonth = ( @inStatementNumber + 2 ) / 2,
@theDay = case @inStatementNumber % 2
when 1 then 16
else 1
end
if( @theMonth >= 13 )
begin
select
@theMonth = 1,
@theYear = @theYear + 1
end
set @outStatementEndDate = datefromparts( @theYear, @theMonth, @theDay )
set @outStatementEndDate = dateadd( day, -1, @outStatementEndDate )
end
end
return isnull( @outStatementEndDate, @inDefaultEndDate )
end
GO
GRANT EXECUTE ON [dbo].[GetVanLineStatementPeriodEndDate] TO [MssExec]
GO