Script to fix transaction errors with invoices in sql2016?

SET ANSI_NULLS ON 
GO   

SET QUOTED_IDENTIFIER ON 
GO       

Create Function [dbo].[CalculateDueDate] (@InvoiceDate Datetime, 
@AgingDate DateTime, --or the due date in AP Invoice 
@DateType Int, 
@DaysNetDue Int) Returns DateTime   

As 
Begin 
Declare @DueDate DateTime   

--DateType 0 
If @datetype = 0 Set @DueDate = @AgingDate   

--DateType 1 
If @Datetype = 1 Set @DueDate = DATEADD (day,@DaysNetDue,@InvoiceDate)   

--DateType 2 
If @DateType = 2   
Begin   
Set @DueDate = DATEADD (day,@DaysNetDue, CONVERT(DATETIME, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE())) ), DATEADD(m, 1, GETDATE()))))   
End   

Return @DueDate 
End     

GO
Was this article helpful?
Thank you for your feedback!
User Icon

Thank you! Your comment has been submitted for approval.