# question

## How to calculate Row count?

Hi all, I have a file with a single header row, details(suppose 100 rows) and a trailer row which contains number(or count) of **rows in the same file excluding the header and trailer row**? How to achieve this? Thanks in advance...

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
What exactly is your question? What are you wanting to achieve?
0 Likes 0 ·
·
And I want to calculate this row count of this file excluding the header and trailer row for the same file and include this in the same file.
0 Likes 0 ·
·
@TRAD r u getting my question?
0 Likes 0 ·
·
Sorta getting it. Is this a file you are importing into a table? What version of SQL are you using?
0 Likes 0 ·
·
i m creating this file from temp table using ssis ... sql server 2005..i m writing a Sql query on the oledb source to get this file ... i have the correct file with header , details and record but i m not able to include this row count in my trailer row.... how to do this ...
0 Likes 0 ·

·
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
@oleg Thx for the answer ... actually i figured out if i use a distinct in SElect statement for table A and no distinct select statement for table B then i will get my desired output ... as if i dont use distinct in table A then i m counting duplicates also where as i m not having any duplicated in the output file from table A.... r u getting me ..... anyways thx alot OLEG.
0 Likes 0 ·
If what @oleg has asked is correct, that you don't infact have a file with the footer right now you can use a union to add a sum column at the end. Pretty simple to do. I will post an example of a query I have recently created to do the same. SELECT Inst , COUNT(Inst) AS Totals FROM docs WHERE status = 'N' GROUP BY INST UNION SELECT 'TOTAL' AS INST , COUNT(*) AS Totals FROM dbo.DOCS WHERE STATUS = 'N' ORDER BY INST ASC

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
@trad i have header and footer in my output but donno how how to get the row count of the file minus the the header and footer row in the same file.
0 Likes 0 ·
·
I think we have enough information on your issue where someone can help out. I however have just finished packing my bags and about to embark on a 5 hour road trip to SQL Saturday #70. I am certain someone will get you the solution to your problem very quickly.
0 Likes 0 ·
·
@abhid, I am so glad that @Oleg was able to get you the results you needed. I hope you continue coming back to ask.sqlservercentral.com to ask questions as well as help others out as well.
0 Likes 0 ·