Should you use a CASE statement? With one Select
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of
Vic Drecchio
Sent: Thursday, February 14, 2013 2:37 PM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] SQL Grouping Question for External BAQ's
I'd take out the GROUP BY and I'd also do a SELECT DISTINCT.
Typing this on my awesome Nokia Windows Phone right now but should be like:
SELECT DISTINCT
InvcDtl.PartNum,
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())) AS "ThisYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-1) AS "LastYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-2) AS "TwoYearsAgo"
FROM InvcDtl ORDER BY 1
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf Of
mitchelljohn
Sent: Thursday, February 14, 2013 4:27 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] SQL Grouping Question for External BAQ's
I am creating a SQL view to be pulled into an external BAQ but I am
completely stuck.
I am able to create the view, however, the current grouping shows the total
for the year for each PartNum record. I am trying to show the total per
PartNum per year. I know that I can do a rollup but I am trying to get each
year's total as a column so that I can pull it into a BAQ as a single line.
If anyone can show me where I am screwing it up I'll buy you a beer in
Nashville at Insights.
SELECT
InvcDtl.PartNum,
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())) AS "ThisYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-1) AS "LastYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-2) AS "TwoYearsAgo"
FROM
InvcDtl
GROUP By InvcDtl.PartNum
Thanks,
John Mitchell
McAuliffe's Industrial
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2238 / Virus Database: 2639/5603 - Release Date: 02/14/13
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2238 / Virus Database: 2639/5603 - Release Date: 02/14/13
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of
Vic Drecchio
Sent: Thursday, February 14, 2013 2:37 PM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] SQL Grouping Question for External BAQ's
I'd take out the GROUP BY and I'd also do a SELECT DISTINCT.
Typing this on my awesome Nokia Windows Phone right now but should be like:
SELECT DISTINCT
InvcDtl.PartNum,
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())) AS "ThisYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-1) AS "LastYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-2) AS "TwoYearsAgo"
FROM InvcDtl ORDER BY 1
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf Of
mitchelljohn
Sent: Thursday, February 14, 2013 4:27 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] SQL Grouping Question for External BAQ's
I am creating a SQL view to be pulled into an external BAQ but I am
completely stuck.
I am able to create the view, however, the current grouping shows the total
for the year for each PartNum record. I am trying to show the total per
PartNum per year. I know that I can do a rollup but I am trying to get each
year's total as a column so that I can pull it into a BAQ as a single line.
If anyone can show me where I am screwing it up I'll buy you a beer in
Nashville at Insights.
SELECT
InvcDtl.PartNum,
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())) AS "ThisYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-1) AS "LastYear",
(SELECT SUM(InvcDtl.SellingShipQty) FROM InvcDtl Where
Year(InvcDtl.ShipDate)=YEAR(GetDate())-2) AS "TwoYearsAgo"
FROM
InvcDtl
GROUP By InvcDtl.PartNum
Thanks,
John Mitchell
McAuliffe's Industrial
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2238 / Virus Database: 2639/5603 - Release Date: 02/14/13
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2238 / Virus Database: 2639/5603 - Release Date: 02/14/13
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]