Total SQL Records in all columns

Asked

Viewed 224 times

0

I need to return the total query records in a column, even repeated, like this: Tabela com Total

However, the query is kind of boring. A query of 106 lines, with several SUM() and with a mandatory ORDER BY. I cannot use GROUP BY in this query because our software that does the processing as the query returns

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 that? I need an accountant. I already use ROW_NUMBER but our software can’t catch the last line, unfortunately I can only run line by line on it. If I can get the total of rows even if repeated in all columns, I can already use the first record to get the information I need

Hugs

  • I figured it out. I switched ROW_NUMBER to @@ROWCOUNT, solved

  • Hello Caio, you can post as an answer and accept your own answer. Take advantage and make a [tour] and better understand how Sopt works. p

  • I confess that even with the Tour I’m a little lost for how to accept the answer itself, excuse me

  • No problem. Below is a chart to write the answer. After posting it, you will see an icon that looks like a certain one (below where it shows the dots). Just click on it. But first you have to create an answer.

  • http://i.stack.Imgur.com/uqJeW.png

  • Thank you Randrade, I have been informed by the system that I can only accept my own answer in 2 days. I will wait. And I will be open to opinions also on the same subject

Show 1 more comment

1 answer

1


I figured it out. I switched ROW_NUMBER to @@ROWCOUNT, solved

Browser other questions tagged

You are not signed in. Login or sign up in order to post.