How to group invoices by total amount and line number with SQL server 2008 : I have a table look like this:
[enter image description here][1]
  [1]: http://i.stack.imgur.com/j1YkF.jpg
I want to auto fill group invoice number if totord accumulation is about 20,000,000 or count distinct invtid maximum is 16. the grouped invoice has to contain all rows of an order or that order will be eliminated. The grouped invoice number will be reset by promdate. Please help me to create a query or a sample SQL code to do it.