Question : Return a "line count" on a sql statement

I want the results of my SQL Query to count the lines returned, reseting the count at each new occurance of Invoice number.  For example if query is "select invoice#, InvAmount from HIST order by invoice#".  I like to see
Invoice#---InvAmount---Count
Inv#123----$500.----------1         // This invoice has 2 distribution lines.  This is line 1 of 2 on invoice#123
Inv#123----$200-----------2        // This invoice has 2 distribution lines.  This is line 2 of 2 on invoice#123
Inv#234----$600-----------1        // This invoice has 1 distribution line.  This is line 1 of 1 on invoice#234
Inv#432----$1000---------1        // This invoice has 1 distribution line.  This is line 1 of 2 on invoice#432
Inv#432----$200----------2         // This invoice has 1 distribution line.  This is line 2 of 2 on invoice#432
Inv#2212---$50-----------1        // This invoice has 1 distribution line.  This is line 1 of 1 on invoice#22212

I don't think this is possible.  I know how to do it Crystal, however I'd like to keep it in  T-SQL Query.

Thanks

Answer : Return a "line count" on a sql statement

does this work for you?

select invoice,  itemamt, dense_rank() Over(Partition by [invoice] order by [Itemamt]) AS LINENO,* from hist h order by invoice, Itemamt)
Random Solutions  
 
programming4us programming4us