识别带有前缀或后缀的重复发票编号

时间:2018-06-04 12:52:44

标签: sql ms-access ms-access-2013

我正在使用Access 2013并尝试识别向供应商支付的重复付款。我使用下面的SQL查询来识别不同类型的重复项,但它没有给出所需的结果,因为有时两个条件不同,如发票号和发票日期。

SELECT 
Base.ID AS SerialNumber, 
Base.CoCd AS CoCode, 
Base.DocumentNo AS DocID, 
Base.ClrngdocNo AS ClearingDoc, 
Base.DocumentType AS DocType, 
Base.Account AS VendorName, 
Base.Reference AS InvoiceNumber, 
Base.DocumentDate AS InvoiceDate, 
Base.GrossInvoiceAmount AS InvAmount

FROM RawData2017TillDate AS Base 
INNER JOIN RawData2017TillDate AS duplicate 
ON (Base.ID <> duplicate.ID) 
AND (Base.Account = duplicate.Account) 
AND (Base.Reference <> duplicate.Reference) 
AND (Base.DocumentDate = duplicate.DocumentDate) 
AND (Base.GrossInvoiceAmount = duplicate.GrossInvoiceAmount)
ORDER BY Base.GrossInvoiceAmount DESC , Base.reference DESC;

我只想要单个查询来识别在发票编号的开头或结尾添加的一个或多个字符的副本,如下例所示 2713565 2713565R, 01456 1456, I-0001118588 1118588

此外,如果我能够获得更好的查询以根据其他标准识别重复项,我们将不胜感激。我正在寻找所有标准的单一查询。

提前致谢!

1 个答案:

答案 0 :(得分:0)

请尝试如下:

我根据前2个字母对发票编号进行分组。

SELECT  
Mid(Base.reference, 1, 2) , count(1)
FROM RawData2017TillDate AS Base 
INNER JOIN RawData2017TillDate AS duplicate 
ON (Base.ID <> duplicate.ID) 
AND (Base.Account = duplicate.Account) 
AND (Base.Reference <> duplicate.Reference) 
AND (Base.DocumentDate = duplicate.DocumentDate) 
AND (Base.GrossInvoiceAmount = duplicate.GrossInvoiceAmount)
group by  Mid(Base.reference, 1, 2) ;