Jump to content

SQL query to export invoices


sgonzalez

Recommended Posts

HI, How is everyone doing? Hope well :)

 

I was looking forward to generate a SQL query to display

 

Invoices paid from feb 01st 2017 to feb 28th 2017, with client name, address, phone, item description, ammount, tax, total

 

 

Can anyone help me? I tried several ways but none one gave me the correct results.

 

 

 

Thanks in advance!!

Link to comment
Share on other sites

it will be something along the lines of...

 

SELECT
tblinvoices.userid,
tblinvoices.id,
tblinvoices.date,
tblinvoices.tax,
tblinvoices.subtotal,
tblinvoices.tax2,
tblinvoices.total,
tblclients.firstname,
tblclients.lastname,
tblclients.address1,
tblclients.address2,
tblclients.city,
tblclients.country,
tblclients.postcode,
tblclients.state,
tblinvoiceitems.description,
tblinvoiceitems.amount,
tblinvoiceitems.taxed
FROM tblinvoices
INNER JOIN tblclients ON tblinvoices.userid = tblclients.id
INNER JOIN tblinvoiceitems ON tblinvoices.id = tblinvoiceitems.invoiceid
WHERE tblinvoices.date BETWEEN '2017-02-01' AND '2017-02-28'

if it were me, i'd be more tempted to modify the Invoices report to query the additional tables, but the above should give you a workable SQL query, though you might have to tweak the output column order.

Link to comment
Share on other sites

Thank you so much Brian :) very helpfull. I tied it up with some additional fields and its working perfect! The only thing that is driving me crazy now is that I was unable to add some customfieldsvalue

 

 

tied up code

SELECT
tblinvoices.userid,
tblinvoices.id,
tblinvoices.date,
tblinvoices.subtotal,
tblinvoices.tax,
tblinvoices.total,
tblclients.firstname,
tblclients.lastname,
tblclients.address1,
tblclients.phonenumber,
tblclients.companyname,
tblclients.country,
tblinvoiceitems.description
FROM tblinvoices
INNER JOIN tblclients ON tblinvoices.userid = tblclients.id
INNER JOIN tblinvoiceitems ON tblinvoices.id = tblinvoiceitems.invoiceid
WHERE tblinvoices.date BETWEEN '2017-02-01' AND '2017-02-28'

 

 

I attach wich customfields I need to complete this.. Tried with different ways and I was unable.. my sql knowledge is so basic

 

 

2.jpg

 

 

Thanks again Brian for such a great help!

customfields.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated