Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2006

Tip: Looking for answers? Try searching our database.

Help with query!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
graeme34 - 26 Mar 2006 17:58 GMT
Hi I have a query is used for the control source of a report, Monthly
Statements

The query was running fine when it was simply showing all debits, now Ive
tried to adapt it by joining another table, transaction which stores details
of all customer payments, as well as supplier payments. Here is the original
query:

SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit
FROM tblVAT INNER JOIN ((tblAccount INNER JOIN tblSalesOrder ON tblAccount.
AccountIndex=tblSalesOrder.AccountIndex) INNER JOIN ((tblDespatch INNER JOIN
tblSalesOrderLine ON tblDespatch.SalesOrderNumber=tblSalesOrderLine.
SalesOrderNumber) INNER JOIN tblSalesInvoice ON tblDespatch.
DespatchNumber=tblSalesInvoice.[Despatch Number]) ON (tblSalesOrder.
SalesOrderNumber=tblDespatch.SalesOrderNumber) AND (tblSalesOrder.
SalesOrderNumber=tblSalesOrderLine.SalesOrderNumber)) ON tblVAT.
VATRate=tblSalesOrderLine.VATRate
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;

After adapting it to 'supposedly' show the details of any payments
it now looks like :

SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit, tblTransaction.TypeOfPosting, IIf([TypeOfPosting]="Customer
Payment",[Amount],0) AS Credit
FROM tblTransaction INNER JOIN (tblVAT INNER JOIN ((tblAccount INNER JOIN
tblSalesOrder ON tblAccount.AccountIndex = tblSalesOrder.AccountIndex) INNER
JOIN ((tblDespatch INNER JOIN tblSalesOrderLine ON tblDespatch.
SalesOrderNumber = tblSalesOrderLine.SalesOrderNumber) INNER JOIN
tblSalesInvoice ON tblDespatch.DespatchNumber = tblSalesInvoice.[Despatch
Number]) ON (tblSalesOrder.SalesOrderNumber = tblSalesOrderLine.
SalesOrderNumber) AND (tblSalesOrder.SalesOrderNumber = tblDespatch.
SalesOrderNumber)) ON tblVAT.VATRate = tblSalesOrderLine.VATRate) ON
tblTransaction.TransactionNumber = tblSalesInvoice.TransactionNumber
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;

The query works but only showing the records that have had a payment. I know
this is because of the INNER JOIN, but could anybody tell me is there a way
to display the result of the first query as well as being able to display any
payment details made from the transaction table??

Thank you
Ken Snell (MVP) - 26 Mar 2006 19:44 GMT
In the QBE window for the query in design view, right-click on the join line
between the two tables of interest. Select Edit from the menu. Choose the
option that allows all records from the parent table, and just the matching
records from the child table. Click OK.

Signature

       Ken Snell
<MS ACCESS MVP>

> Hi I have a query is used for the control source of a report, Monthly
> Statements
[quoted text clipped - 55 lines]
>
> Thank you
graeme34 - 26 Mar 2006 20:15 GMT
Thank you Ken ! (and John)

>In the QBE window for the query in design view, right-click on the join line
>between the two tables of interest. Select Edit from the menu. Choose the
[quoted text clipped - 6 lines]
>>
>> Thank you
John Spencer - 26 Mar 2006 19:49 GMT
You might try changing the join to an outer join.  TEST the following which uses
a right join. If this works it will return all records in the other tables.

SELECT DISTINCT tblAccount.AccountIndex, tblSalesOrder.CustomerOrderNumber,
tblSalesInvoice.InvoiceDate, tblSalesInvoice.SalesInvoiceNumber,
tblSalesInvoice.TotalNett, tblVAT.VATValue, [TotalNett]*(([VatValue]/100)+1)
AS Debit, tblTransaction.TypeOfPosting, IIf([TypeOfPosting]="Customer
Payment",[Amount],0) AS Credit
FROM tblTransaction RIGHT JOIN (tblVAT INNER JOIN ((tblAccount INNER JOIN
tblSalesOrder ON tblAccount.AccountIndex = tblSalesOrder.AccountIndex) INNER
JOIN ((tblDespatch INNER JOIN tblSalesOrderLine ON tblDespatch.
SalesOrderNumber = tblSalesOrderLine.SalesOrderNumber) INNER JOIN
tblSalesInvoice ON tblDespatch.DespatchNumber = tblSalesInvoice.[Despatch
Number]) ON (tblSalesOrder.SalesOrderNumber = tblSalesOrderLine.
SalesOrderNumber) AND (tblSalesOrder.SalesOrderNumber = tblDespatch.
SalesOrderNumber)) ON tblVAT.VATRate = tblSalesOrderLine.VATRate) ON
tblTransaction.TransactionNumber = tblSalesInvoice.TransactionNumber
ORDER BY tblAccount.AccountIndex, tblSalesInvoice.InvoiceDate;

> Hi I have a query is used for the control source of a report, Monthly
> Statements
[quoted text clipped - 46 lines]
> --
> Message posted via http://www.accessmonster.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.