# export to excel and name worksheets

**URL:** <https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582>\
**Category:** Toad for SQL Server\
**Created:** [July 22, 2011, 11:24am UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582 "2011-07-22T11:24:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shanah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Shanah](https://forums.toadworld.com/u/Shanah)\
**Post date:** [July 22, 2011, 11:24am UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/1 "2011-07-22T11:24:27Z")

</div>

My office does not have a good datawarehouse and i can only query against 999 records at a time.

how can i have it loop to run the next set of records and export to excel and name each sheet for the query results, or better yet append to the end of each query?

Most files I’m running are in the 2k-5k records, so multiple queries are needed.

Also, one of my fields is a comment field, so i’m afraid if i export to a cvs i will truncate data.

Thank you  
Shanah

---

<div class="post-metadata">

**Author:** ![Debbie\_Peabody](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/debbie_peabody/32/18_2.png) [@Debbie\_Peabody](https://forums.toadworld.com/u/Debbie_Peabody)\
**Post date:** [July 22, 2011, 1:04pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/2 "2011-07-22T13:04:35Z")

</div>

If you export to the same Excel file you have it append a new unnamed worksheet. There currently is no way to append the data (Although that is a requested enhancement).

To export to a new worksheet you can do this in one of two ways.

1. Using the export wizard, use the add query type. Add a script that containis multiple SQL. Each select result will be sent to new worksheet. (Note: If you use a named worksheet it will over write it.

IE: Select \* from table limit rows 1 -999;  
select \* from table limit rows 1000 - 19999

The Syntax is not correct but this just shows the idea.

1. Use automation to execute a loopdataset. Here you can use bind variables in your select.

I’d choose item 1 if you can put together the SQL without binds.

Debbie

---

<div class="post-metadata">

**Author:** ![Shanah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Shanah](https://forums.toadworld.com/u/Shanah)\
**Post date:** [July 22, 2011, 1:20pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/3 "2011-07-22T13:20:32Z")

</div>

I use Toad and this is my first week using this tool. My SQL has primarly been via Access.

Can I write the export function in code? I’m not sure how to use the export wizard.

---

<div class="post-metadata">

**Author:** ![Debbie\_Peabody](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/debbie_peabody/32/18_2.png) [@Debbie\_Peabody](https://forums.toadworld.com/u/Debbie_Peabody)\
**Post date:** [July 22, 2011, 1:40pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/4 "2011-07-22T13:40:39Z")

</div>

You are connecing to SQL Server, correct? Not access. If you are connectig to Access you need to use Toad for Data Analysts.

if you are using SQL Server, you can write a block of code and enter as Query to Export Wizard. See attached screenshots.

Debbie

 ![export2.png](https://global.discourse-cdn.com/quest/original/2X/8/86f28fc63f326d01cc9a77332369ec5092ef41fb.png)

---

<div class="post-metadata">

**Author:** ![Debbie\_Peabody](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/debbie_peabody/32/18_2.png) [@Debbie\_Peabody](https://forums.toadworld.com/u/Debbie_Peabody)\
**Post date:** [July 22, 2011, 1:40pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/5 "2011-07-22T13:40:39Z")

</div>

You are connecing to SQL Server, correct? Not access. If you are connectig to Access you need to use Toad for Data Analysts.

if you are using SQL Server, you can write a block of code and enter as Query to Export Wizard. See attached screenshots.

Debbie

 ![export1.png](https://global.discourse-cdn.com/quest/original/2X/b/bfdbe0308ecee48c42e077a526bd3e13ca2e4f64.png)

---

<div class="post-metadata">

**Author:** ![Shanah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Shanah](https://forums.toadworld.com/u/Shanah)\
**Post date:** [July 22, 2011, 2:47pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/6 "2011-07-22T14:47:47Z")

</div>

Debbie,  
I don’t think i have the export wizard:( I only have Data Pump Export Wizard.

Is there not a command line I can add to the end of my code that will do this?

thanks so much for you help!

---

<div class="post-metadata">

**Author:** ![hfreeman](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/hfreeman/32/54_2.png) [@hfreeman](https://forums.toadworld.com/u/hfreeman)\
**Post date:** [July 22, 2011, 7:40pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/7 "2011-07-22T19:40:16Z")

</div>

Shanah, I am a user… So, I have the following questions  
 ![image001.gif](https://global.discourse-cdn.com/quest/original/1X/c419a4884cb60937895dfef6b4b6862a4a679db6.gif)

---

<div class="post-metadata">

**Author:** ![hfreeman](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/hfreeman/32/54_2.png) [@hfreeman](https://forums.toadworld.com/u/hfreeman)\
**Post date:** [July 22, 2011, 7:40pm UTC](https://forums.toadworld.com/t/export-to-excel-and-name-worksheets/14582/8 "2011-07-22T19:40:16Z")

</div>

Shanah, I am a user… So, I have the following questions  
 ![image002.jpeg](https://global.discourse-cdn.com/quest/original/1X/ca60ef1b55129d126c1774d4371b31a0a5bd7429.jpeg)
