Skip to Content
author's profile photo Former Member
Former Member

Sales query using multiple variables.

Hi,

I have a problem I'm trying to solve with a query to report sales in the last 7 days.

The query itself has to sales by day, by product and also by country.

This means that I require a separate row for each day, each product sold on each day, and each country every product was sold in on each day.

For example:

2/2/2012 - Product1 - Australia - Sales

2/2/2012 - Product1 - United States - Sales

2/2/2012 - Product 2 - Australia - Sales

3/2/2012 - Product 1 - Australia - Sales

3/2/2012 - Product 2 - Australia - Sales

3/2/2012 - Product 2 - United States - Sales

Hopefully this makes sense!

I've got to the point where I can see all sales for the week in sum but I need to be able to break it down to a more detailed level as described above.

The question I would really love answering is how I would achieve this query. Do I need many different queries and then use UNION to combine? Is there a simple solution?

Hopefully you can help me out! Please let me know if you need me to explain in any more detail.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 04, 2012 at 11:19 PM

    Hi,

    Welcome you post on the forum.

    Try:

    SELECT T1.DocDate, T1.Itemcode, T2.Country, Sum(T1.LineTotal) 'Sales'

    FROM OINV T0

    INNER JOIN INV1 T1 ON T1.DocEntry = T0.DocEntry

    LEFT JOIN OCRD T2 ON T2.CardCode = T0.CardCode

    WHERE DateDiff(DD,T1.Docdate,Getdate())<=7

    GROUP BY T1.DocDate, T1.Itemcode,T2.Country

    Thanks,

    Gordon

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 04, 2012 at 03:26 PM

    Does anyone have any suggestions? It would be greatly appreciated.

    Please let me know if you need me to explain the problem in any more detail.

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.