Total SQL Records in all columns

0

I need to return the total records of the query in a column, repeated same, type this:

However, the query is a bit annoying. A query of 106 rows, with multiple SUM () and with a mandatory ORDER BY. I can not use GROUP BY in this query because our software that does the treatments according to the return of the query

A piece of code:

SELECT ROW_NUMBER() OVER (ORDER BY B1_MASTER, B1_COD) AS ID,
   B1_COD,
   B1_DESC, 
   B1_CATEG, 
   B1_MASTER, 
   A2_COMPRAD,
   ISNULL((SELECT Sum(C6_QTDVEN * C6_PRCVEN) 
           FROM   SC6010 SC6, 
                  SF4010 SF4, 
                  SC5010 SC5 
           WHERE  C6_FILIAL = '01' 
                  AND C6_PRODUTO = B1_COD 
                  AND SC6.D_E_L_E_T_ <> '*' 
                  AND C5_FILIAL = C6_FILIAL 
                  AND C5_NUM = C6_NUM 
                  AND C5_EMISSAO BETWEEN '20160401' AND '20160404' 
                  AND C5_TIPO = 'N' 
                  AND C5_MODAL = '2' 

How would I do this? I need an accountant. I already use ROW_NUMBER but our software can not get the last line, unfortunately I can only run row by line on it. If I get the total number of rows even if repeated in all columns, I can already use the first record to get the information I need

Hugs

    
asked by anonymous 05.04.2016 / 17:34

1 answer

1

I already found out. I've changed ROW_NUMBER by @@ ROWCOUNT, resolved

    
05.04.2016 / 18:03