F
Fred
I want to use a dataset so that I can obtain data from a number of sources
and put it into one table. Using dataadaptors this seems to work well.
Now I have a table (Forecast) in the dataset with columns:
Rep, Area, Period, Qty.
I want to display this data on a datagrid like:
Rep, Period1_Qty, Period2_Qty, .. Period7_Qty
where the period1_Qty is the sum of the Qtys for that Rep and for a
particular period.
I can do this in SQL by:
SELECT Rep, SUM(Qty1), SUM(Qty2), ... SUM(Qty7) FROM
(SELECT F1.Rep, SUM(F1.Qty) AS Qty1, 0 AS Qty2, ..., 0 AS Qty7
FROM Forecast F1 WHERE F1.Period=1 GROUP BY F1.Rep
UNION ALL
SELECT F2Rep, 0 as Qty1, SUM(F2.Qty) AS Qty2, 0 AS Qty3, ...,0 AS Qty7
FROM Forecast F2 WHERE F2.Period=2 GROUP BY F2.Rep
UNION ALL
....
UNION ALL
SELECT F7.Rep, 0 AS Qty1, 0 AS Qty2, ... , SUM(F1.Qty) AS Qty7
FROM Forecast F7 WHERE F7.Period=2 GROUP BY F7.Rep)
GROUP BY Rep
The above statement would vary depending on which periods to display or
whther to display by Rep or Area.
How can I create a table/view by applying a SQL statement like this to a
Dataset?
Thanks
Fred
and put it into one table. Using dataadaptors this seems to work well.
Now I have a table (Forecast) in the dataset with columns:
Rep, Area, Period, Qty.
I want to display this data on a datagrid like:
Rep, Period1_Qty, Period2_Qty, .. Period7_Qty
where the period1_Qty is the sum of the Qtys for that Rep and for a
particular period.
I can do this in SQL by:
SELECT Rep, SUM(Qty1), SUM(Qty2), ... SUM(Qty7) FROM
(SELECT F1.Rep, SUM(F1.Qty) AS Qty1, 0 AS Qty2, ..., 0 AS Qty7
FROM Forecast F1 WHERE F1.Period=1 GROUP BY F1.Rep
UNION ALL
SELECT F2Rep, 0 as Qty1, SUM(F2.Qty) AS Qty2, 0 AS Qty3, ...,0 AS Qty7
FROM Forecast F2 WHERE F2.Period=2 GROUP BY F2.Rep
UNION ALL
....
UNION ALL
SELECT F7.Rep, 0 AS Qty1, 0 AS Qty2, ... , SUM(F1.Qty) AS Qty7
FROM Forecast F7 WHERE F7.Period=2 GROUP BY F7.Rep)
GROUP BY Rep
The above statement would vary depending on which periods to display or
whther to display by Rep or Area.
How can I create a table/view by applying a SQL statement like this to a
Dataset?
Thanks
Fred