MeanJoeGreen13
IS-IT--Management
- Jan 6, 2008
- 15
I am working on a sql function to be fed an invoice number, then calculate the difference between the current system date and the last GL posting "GLPOSTDT"
The function is not returning any results as of yet...see attached code
The function is not returning any results as of yet...see attached code
Code:
USE [TEST]
GO
/****** Object: UserDefinedFunction [dbo].[CheckInvoiceDate] Script Date: 01/08/2008 11:19:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[CheckInvoiceDate] (@invoicecode varchar(21))
RETURNS int AS
BEGIN
declare @NumofDays int
SET @NumofDays =
( SELECT datediff(day, max(rm2.GLPOSTDT), getdate())
FROM rm20201 rm2
JOIN sop30200 sop on rm2.aptodcnm = sop.sopnumbe
WHERE aptodcnm=@invoicecode and sop.soptype = 3) +
( SELECT datediff(day, max(rm2.GLPOSTDT), getdate())
FROM rm30201 rm2
JOIN sop30200 sop on rm2.aptodcnm = sop.sopnumbe
WHERE aptodcnm=@invoicecode and sop.soptype = 3)
return @NumofDays
END