I know I’m supposed to filter on ‘RelatedToFile’, (does anyone know the filter value for APInvDtl?) but I don’t think that matters yet as I’m getting an error when I test.
There are plenty of questions and complaints here related to TranGLC, but I haven’t found anything that helps yet.
I’m closer now, but I’m still getting two rows returned for each invoice line…one record type ‘A’ and one record type ‘R’. Once I figure out which one to get rid of I might have this solved.
select
[TranGLC].[Company] as [TranGLC_Company],
[TranGLC].[RelatedToFile] as [TranGLC_RelatedToFile],
[Vendor].[Name] as [Vendor_Name],
[GLJrnDtl].[PostedDate] as [GLJrnDtl_PostedDate],
[APInvHed].[ApplyDate] as [APInvHed_ApplyDate],
[GLJrnDtl].[APInvoiceNum] as [GLJrnDtl_APInvoiceNum],
[TranGLC].[Key3] as [TranGLC_Key3],
[APInvDtl].[Description] as [APInvDtl_Description],
[TranGLC].[JournalCode] as [TranGLC_JournalCode],
[TranGLC].[JournalNum] as [TranGLC_JournalNum],
[TranGLC].[JournalLine] as [TranGLC_JournalLine],
[TranGLC].[BookCreditAmount] as [TranGLC_BookCreditAmount],
[TranGLC].[BookDebitAmount] as [TranGLC_BookDebitAmount],
[GLAccount].[SegValue1] as [GLAccount_SegValue1],
[GLAccount].[AccountDesc] as [GLAccount_AccountDesc]
from Erp.TranGLC as [TranGLC]
inner join Erp.GLJrnDtl as [GLJrnDtl] on
TranGLC.Company = GLJrnDtl.Company
and TranGLC.FiscalCalendarID = GLJrnDtl.FiscalCalendarID
and TranGLC.FiscalYear = GLJrnDtl.FiscalYear
and TranGLC.JournalCode = GLJrnDtl.JournalCode
and TranGLC.JournalNum = GLJrnDtl.JournalNum
and TranGLC.JournalLine = GLJrnDtl.JournalLine
inner join Erp.Vendor as [Vendor] on
GLJrnDtl.Company = Vendor.Company
and GLJrnDtl.VendorNum = Vendor.VendorNum
left outer join Erp.APInvDtl as [APInvDtl] on
TranGLC.Company = APInvDtl.Company
and TranGLC.Key1 = CONVERT( nvarchar(50), APInvDtl.VendorNum)
and TranGLC.Key2 = CONVERT( nvarchar(50), APInvDtl.InvoiceNum)
and TranGLC.Key3 = CONVERT( nvarchar(50), APInvDtl.InvoiceLine)
left outer join Erp.APInvHed as [APInvHed] on
APInvDtl.Company = APInvHed.Company
and APInvDtl.VendorNum = APInvHed.VendorNum
and APInvDtl.InvoiceNum = APInvHed.InvoiceNum
inner join Erp.GLAccount as [GLAccount] on
GLAccount.Company = TranGLC.Company
and GLAccount.SegValue1 = TranGLC.SegValue1
order by TranGLC.JournalNum Desc
Combined the knowledge from these threads to achieve the result: