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

Year as a Selectable Parameter

Hi Guys,

I have the following query to show me the sales per month by country, However at the moment I have the year is hard coded in and I would like to have it as a selectable parameter, I am having a complete brain blank and cannot get it to work, could someone please point me in the right direction.

SELECT * FROM (

SELECT DISTINCT Country, SUM(SalesYTD) AS YTDSales, [MONTH] FROM

(

SELECT DISTINCT T2.Country, SUM(T1.Debit) - SUM(T1.Credit) AS SalesYTD, T1.Shortname, MONTH(T1.RefDate) AS [Month] FROM JDT1 T1 INNER JOIN OCRD T2 ON T1.ShortName = T2.CardCode

WHERE Year(T1.RefDate) = 2011 AND T1.TransType IN ('13','14') and T2.CardType = 'C'

GROUP BY T2.Country, T1.Shortname, MONTH(T1.RefDate))

sYTD

GROUP BY Country,[MONTH]

) Q

PIVOT (SUM([YTDSales]) FOR [Month] IN

([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P

Any help gratefully appreciated

Kind regards

Sean

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Dec 08, 2011 at 12:09 PM

    Hi Sean

    try this

    SELECT * FROM (
    SELECT DISTINCT Country, SUM(SalesYTD) AS YTDSales, MONTH FROM
    (
    SELECT DISTINCT T2.Country, SUM(T1.Debit) - SUM(T1.Credit) AS SalesYTD, T1.Shortname, MONTH(T1.RefDate) AS Month FROM JDT1 T1 INNER JOIN OCRD T2 ON T1.ShortName = T2.CardCode
    WHERE Year(T1.RefDate) = '[%0]' AND T1.TransType IN ('13','14') and T2.CardType = 'C'
    GROUP BY T2.Country, T1.Shortname, MONTH(T1.RefDate))
    
    sYTD
    GROUP BY Country,MONTH
    ) Q
    PIVOT (SUM(YTDSales) FOR Month IN
    ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P

    Edited by: Fasolis Vasilios on Dec 8, 2011 1:10 PM

    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.