Desktop version

Main > Forum > Applications > 1C:AccountingSuite > JOIN for matching of receipts with salesinvoices

Forum

Search UsersRules
JOIN for matching of receipts with salesinvoices
#1
Interested
Points:: 0
Joined:: Nov 10, 2011

I try to make a report where I need a table with sales invoices and in the same row date and amount of receipts. If I write a code:

Code
SEL ECT
   ReceiptLineItems.Ref,
   ReceiptLineItems.Payment,
   ReceiptLineItems.Ref.Date,
   SalesInvoice.Ref AS Ref1
FR OM
   Document.Receipt.LineItems AS ReceiptLineItems
      LEFT JOIN Document.SalesInvoice AS SalesInvoice
      ON ReceiptLineItems.Document = SalesInvoice.Ref


I get all Lines of receipt to the salesinvoice, also Lines to another salesinvoice, if the sales invoice was "mentioned" in the document receipt.
Where can be an error?

Profile
#2
Guest
Points::
Joined::

You have wrong order of joined tables, if you need SalesInvoices with Payments you need to place SalesInvoices first in FROM clause and then join payments to it:

Code
SELECT
    ReceiptLineItems.Ref,
    ReceiptLineItems.Payment,
    ReceiptLineItems.Ref.Date,
    SalesInvoice.Ref AS Ref1
FROM
   Document.SalesInvoice AS SalesInvoice
        LEFT JOIN Document.Receipt.LineItems AS ReceiptLineItems 
        ON ReceiptLineItems.Document = SalesInvoice.Ref

Profile
#3
Just came
Points:: 7
Joined:: Mar 15, 2012

May be you need this:

Code
SEL ECT
   COUNT(DISTINCT ReceiptLineItems.Ref),
   ReceiptLineItems.Ref.Date,
   ReceiptLineItems.Document AS Ref1
FR OM
   Document.Receipt.LineItems AS ReceiptLineItems
GROUP BY
   ReceiptLineItems.Ref.Date,
   ReceiptLineItems.Document

Profile
#4
Interested
Points:: 0
Joined:: Nov 10, 2011

bugt,

it hasn't fixed the problem, I have the same output table.

Mikhail, primarely I need a list of all sales invoices, and information with date of payment (receipt). But it doesn't work

Profile
#5
Interested
Points:: 15
Joined:: Oct 27, 2011

use OUTER JOIN (left, right). You can google how to use it.

Profile
#6
Active user
Points:: 23
Joined:: Jul 29, 2011

Lioudmila, there might be some issues with grouping in your report. I emailed to you a sample database where it all works.

Profile
#7
Interested
Points:: 0
Joined:: Nov 10, 2011

Yes, Konstantin, there was an error in grouping of fields. This way it works:

Code
SEL ECT
   ReceiptLineItems.Ref AS Receipt,
   ReceiptLineItems.Payment,
   SalesInvoice.Ref AS Invoice,
   SalesInvoice.DocumentTotalRC AS InvoiceAmount,
   ReceiptLineItems.Ref.Date AS PaymentDate
FR OM
   Document.Receipt.LineItems AS ReceiptLineItems
      LEFT JOIN Document.SalesInvoice AS SalesInvoice
      ON ReceiptLineItems.Document = SalesInvoice.Ref


But I have one more question: how can I change the query in order to get all invoices, even if they are not payed?

Profile
#8
Interested
Points:: 15
Joined:: Oct 27, 2011

FULL OUTER JOIN? I bet it helps.

Profile
#9
Interested
Points:: 0
Joined:: Nov 10, 2011

Yep! Thanks, Alexey!

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.