DECLARE @foo TABLE ( itemid int, proddte date, qty int );...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Database Administrators

Q&A for database professionals who wish to improve their database skills and learn from others in the community

DECLARE @foo TABLE
(
 itemid int, 
 proddte date,
 qty int
);

INSERT @foo(itemid,proddte,qty) VALUES
(1,'20140101',5),(1,'20140102',7),(2,'20150101',10);

SELECT itemid, proddte, SUM(qty)
  FROM @foo GROUP BY GROUPING SETS((),(itemid,proddte));

SELECT itemid, proddte, SUM(qty)
  FROM @foo GROUP BY ROLLUP((itemid,proddte));

SELECT itemid, proddte, SUM(qty)
  FROM @foo GROUP BY ROLLUP(itemid,proddte);

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results