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.
| 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 resultIt'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 ALLSELECT Firstname, Lastname, Salary FROM oursalarytableUNION ALLSELECT '', 'Total Salary', SUM(Salary) FROM oursalarytable This would normally be a party of a presentation layer though and not in a query like this.- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
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 ALLSELECT Firstname, Lastname, Salary FROM oursalarytableUNION ALLSELECT '', 'Total Salary', SUM(Salary) FROM oursalarytable This would normally be a party of a presentation layer though and not in a query like this.- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
Thanks for your assistance |
 |
|
|
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.- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
 |
|
|
|
|
|
|
|