I have an order table like this
ID OrderNumber Item Quantity Subtotal OrderedBy 1 2012-0001-12 Barbie 1 10 Thomas 2 2012-0001-12 Ken 2 20 Thomas 3 2012-0001-23 Mickie 4 28 Thomas 4 2012-0001-23 Minnie 3 21 Thomas 5 2012-0002-12 Barbie 1 10 Peter 6 2012-0003-01 Cake 1 12 Thomas 7 2012-0003-02 Wine 1 70 Thomas
In the OrderNumber the first two parts, that is for the first row 2012-001, is the actual order id.
The last part appended is the SupplierID which is not relevant in this case.
So this table now has three Orders
OrderNumber OrderCount Total OrderedBy 2012-0001 4 79 Thomas 2012-0002 1 10 Peter 2012-0003 2 82 Thomas
Currently I am looping through the DataTable after SELECTing everything from database and adding it to another generic list when 2012-0001 changes to 2012-0002. Meanwhile I am also adding the itemCount and total in the loop.
Is there a way to get the orders in a table(sql) or as an enumerable collection(linq) without this much hassle?
If you are just looking to create your second table, then you could try the following:
This makes the assumption that a single order will always be done by the same person.