SELECT [Electronic Payment].[Association ID], [Electronic Payment].[EP Vendor ID], [EP Vendor Names].[EP Vendor Name], [Electronic Payment].[Total EP Amount], [Electronic Payment].[EP Account Code], [Electronic Payment].[EP Date], [Electronic Payment].[EP Reference], [Electronic Payment].[EP Code 1], [Electronic Payment].[EP Amount to Code 1], [Electronic Payment].[EP Code 2], [Electronic Payment].[EP Amount to Code 2], [Electronic Payment].[EP Code 3], [Electronic Payment].[EP Amount to Code 3], [Electronic Payment].[EP ID], [Electronic Payment].[Invoice Date], [Electronic Payment].[Number Of Codes], [Electronic Payment].Frequency, [Electronic Payment].[Invoice Required], [total ep amount]-([ep amount to code 1]+[ep amount to code 2]+[ep amount to code 3]) AS [Distribution Balance], [Total EP Amount]*1 AS [ep account code amount]
FROM [EP Vendor Names] INNER JOIN [Electronic Payment] ON [EP Vendor Names].[EP Vendor ID] = [Electronic Payment].[EP Vendor ID]
WHERE ((([Electronic Payment].[EP Date])<Date()-30));