Invoices and account distributions are just one of the many examples that is covered in KB 42536 about SQL joins to distribution accounts.
Review article 42536 for more information on how to write code to return a GL distribution for a check.
To join invoices and account distributions, you will primarily use BBDISTRIBUTIONS from the example. PARENTOBJECTTYPE is a foreign key to multiple types, so it must be filtered using the values listed in the article on bbMetaObjects enum from the VBA/API help. For example, 268 is the value for an APInvoice.
Disclaimer: Blackbaud provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Structured Query Language and the tools used to create and modify SQL statements and Crystal Reports. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.