Hi
I have a query but do not have date field I can use other than year and month
I want to try and get to wither creating a query I can use with Crystal or Excel where a user can select between two dates using the month and year.
so I would have, if 2 dates were selected say Jan2014 to April2015 to display in a row the sum of sum of quantityused underneath each month
Name Jan2014 Feb2014 etc....... March2015 April2015
Sum of quatityused under each month
Any ideas if I can produce this in SQL at all, below is the view I have so far, any ideas please
SELECT TOP (100) PERCENT dbo.ProductAnalysis.CalendarYear, DATENAME(month, DATEADD(month, dbo.ProductAnalysis.CalendarMonth - 1, 0)) AS Monthname,
dbo.Product.ProductCode, dbo.Product.Description, dbo.ProductAnalysis.QuantityUsed, dbo.ProductGroup.Name
FROM dbo.Product INNER JOIN
dbo.ProductAnalysis ON dbo.Product.ProductID = dbo.ProductAnalysis.ProductID INNER JOIN
dbo.ProductGroup ON dbo.Product.ProductGroupID = dbo.ProductGroup.ProductGroupID INNER JOIN
dbo.Stock ON dbo.Product.ProductID = dbo.Stock.ProductID
WHERE (dbo.ProductGroup.Level1ID = 3000) AND (dbo.ProductGroup.ProductGroupID <> 3080) AND (dbo.Stock.BranchID = 1)
ORDER BY dbo.ProductAnalysis.CalendarYear, Monthname, dbo.ProductGroup.Name
I have a query but do not have date field I can use other than year and month
I want to try and get to wither creating a query I can use with Crystal or Excel where a user can select between two dates using the month and year.
so I would have, if 2 dates were selected say Jan2014 to April2015 to display in a row the sum of sum of quantityused underneath each month
Name Jan2014 Feb2014 etc....... March2015 April2015
Sum of quatityused under each month
Any ideas if I can produce this in SQL at all, below is the view I have so far, any ideas please
SELECT TOP (100) PERCENT dbo.ProductAnalysis.CalendarYear, DATENAME(month, DATEADD(month, dbo.ProductAnalysis.CalendarMonth - 1, 0)) AS Monthname,
dbo.Product.ProductCode, dbo.Product.Description, dbo.ProductAnalysis.QuantityUsed, dbo.ProductGroup.Name
FROM dbo.Product INNER JOIN
dbo.ProductAnalysis ON dbo.Product.ProductID = dbo.ProductAnalysis.ProductID INNER JOIN
dbo.ProductGroup ON dbo.Product.ProductGroupID = dbo.ProductGroup.ProductGroupID INNER JOIN
dbo.Stock ON dbo.Product.ProductID = dbo.Stock.ProductID
WHERE (dbo.ProductGroup.Level1ID = 3000) AND (dbo.ProductGroup.ProductGroupID <> 3080) AND (dbo.Stock.BranchID = 1)
ORDER BY dbo.ProductAnalysis.CalendarYear, Monthname, dbo.ProductGroup.Name