SQL Query to use in report builder 3.0: grouping results together -
i trying product sales report shows example
itemid salesdate qty_sold item1 1/9/14 3 item1 1/9/14 2 item1 1/9/14 5 item2 2/9/14 2 item3 4/9/14 1
the problem have because sales of example 3 on monday made of 1-3 different sales orders, can show multiple lines , not group want.
i want product report shows item id, date of purchase , total sold on day, not list of sales include item if makes sense?
thanks in advance
more details:
select st.orderdate, sl.itemid, sl.qty salestable st inner join salesline sl on salestable.salesid = salesline.salesid
currently, displays results follows.
orderdate itemid qty 1/1/14 101 1 1/1/14 101 3 1/1/14 102 1
i group rows if possible show 1 line per date & itemid. doesn't work because separate lines in database have different order numbers etc.
orderdate itemid qty 1/1/14 101 4 1/1/14 102 1 2/1/14 102 5 2/1/14 101 2
if cant done, grouping type within report builder suffice cant see way of doing it!
cheers
for sql have included in question need use aggregate function sum group statement.
select st.orderdate, sl.itemid, sum(sl.qty) salestable st inner join salesline sl on salestable.salesid = salesline.salesid group st.orderdate, sl.itemid
you mention other fields prevent this, don't include them in example anywhere. if modify question include these come definitive answer.
based on comment date, 1 possible solution:
select dateadd(dd, 0, datediff(dd, 0, st.orderdate)), sl.itemid, sum(sl.qty) salestable st inner join salesline sl on salestable.salesid = salesline.salesid group dateadd(dd, 0, datediff(dd, 0, st.orderdate)), sl.itemid
Comments
Post a Comment