Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Header and Footer

Author  Topic 

Lakiesha31
Starting Member

6 Posts

Posted - 2010-06-22 : 09:22:16
Hello,


I am trying to add a header and footer statement to my query to count the number of records within my query as a result

It's a text file that I will have run my results to, but I am not sure of how I should add in my Header and footer information.

What I have as an example would be Header|number of records|total amount|||||||

how would I program that in my script?

Thanks for your assistance

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-22 : 09:47:32
You can create a union all statement, just make sure that the header and footer-queries have the same number of clumns. Sort of like this:
SELECT 'Firstname', 'Lastname', 'Salary'
UNION ALL
SELECT Firstname, Lastname, Salary FROM oursalarytable
UNION ALL
SELECT '', 'Total Salary', SUM(Salary) FROM oursalarytable
This would normally be a party of a presentation layer though and not in a query like this.

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-06-22 : 10:46:57
see

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/10/10/export-to-excel-with-column-names.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lakiesha31
Starting Member

6 Posts

Posted - 2010-06-22 : 11:30:49
Well how would I input this in the query? Or is it possible to do? What are your suggestions? I have ran my query to a txt file without the footer...my header consist of my Column Names...but I still need a record count in my header and footer. My record count has to match the number of records that SQL found whent he query was run -the header and footer.

quote:
Originally posted by Lumbago

You can create a union all statement, just make sure that the header and footer-queries have the same number of clumns. Sort of like this:
SELECT 'Firstname', 'Lastname', 'Salary'
UNION ALL
SELECT Firstname, Lastname, Salary FROM oursalarytable
UNION ALL
SELECT '', 'Total Salary', SUM(Salary) FROM oursalarytable
This would normally be a party of a presentation layer though and not in a query like this.

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com




Thanks for your assistance
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-23 : 02:04:18
Can you please post your query and the exact layout of the file you wish to create? Please add [ code ] tags around your query AND the layout of the file.

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page
   

- Advertisement -