# Automation

**URL:** <https://forums.toadworld.com/t/automation/34818>\
**Category:** Toad for SQL Server\
**Created:** [January 12, 2016, 3:59am UTC](https://forums.toadworld.com/t/automation/34818 "2016-01-12T03:59:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![EngMony](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@EngMony](https://forums.toadworld.com/u/EngMony)\
**Post date:** [January 12, 2016, 3:59am UTC](https://forums.toadworld.com/t/automation/34818/1 "2016-01-12T03:59:41Z")

</div>

Hello ,

I need to execute script and send result by mail

from automation tab, i drag execute scirpt and paste the script

after that i drag send mail and configure mail server setting

but i didn’t find from where I define that he mail will contain the script outlook?

Also I need to know when i use LINK SQL file ? i didn’t understand the benfit from it

Thanks

---

<div class="post-metadata">

**Author:** ![Kelly.Chen](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@Kelly.Chen](https://forums.toadworld.com/u/Kelly.Chen)\
**Post date:** [January 13, 2016, 3:03am UTC](https://forums.toadworld.com/t/automation/34818/2 "2016-01-13T03:03:51Z")

</div>

Hi,

You can use "Select to File" instead of "Execute Script".

Then click "Add attachment" to select the result file, or setting the result file in "Use file for body".

 ![Send Email.png](https://global.discourse-cdn.com/quest/original/2X/1/135d15598880cac4d6928bf7d8ff46981f50d90d.png)

When check the Link SQL file checkbox, this means that toad will execute script from file. You can select file as below.

 ![Link SQL File.png](https://global.discourse-cdn.com/quest/original/2X/f/f098505008882167a704a9727ede97ddd83b83f3.png)

For more Send Email details, please refer the help document.

Open the Help doc : Help -\>Toad Help

Path: Automate Tasks | Tutorials | Automate Sending Email

If you have more questions, please feel free to contact us.

Regards,

Kelly

---

<div class="post-metadata">

**Author:** ![PrashantGijare](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@PrashantGijare](https://forums.toadworld.com/u/PrashantGijare)\
**Post date:** [December 19, 2017, 11:20am UTC](https://forums.toadworld.com/t/automation/34818/3 "2017-12-19T11:20:37Z")

</div>

Hi Kelly

Please see the attached image for Select to File in my automation window. I am using Toad for SQL Server Expert Edition V 6.5. Nowhere I'm seeing the option to attach. I'm looking to execute a script which has bunch of sql statements and have the results of all statements logged to a file. All statements are just select statements.

Let me know your thoughts.

Thanks

Prashant

 ![Select_to_file.png](https://global.discourse-cdn.com/quest/original/2X/1/19155cd777079bf030fecd56a03beffbca8d05a5.png)

---

<div class="post-metadata">

**Author:** ![michael](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@michael](https://forums.toadworld.com/u/michael)\
**Post date:** [December 20, 2017, 10:23pm UTC](https://forums.toadworld.com/t/automation/34818/4 "2017-12-20T22:23:00Z")

</div>

Hi Prashant,

 ![attached.png](https://global.discourse-cdn.com/quest/original/2X/1/1c126167a713c6d499213a9af02864cf93643fca.png)

Did this button what you want?

Michael

---

<div class="post-metadata">

**Author:** ![PrashantGijare](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@PrashantGijare](https://forums.toadworld.com/u/PrashantGijare)\
**Post date:** [December 21, 2017, 4:17am UTC](https://forums.toadworld.com/t/automation/34818/5 "2017-12-21T04:17:54Z")

</div>

Hi Michael,

That button is to select a sql file that needs to be executed.I am looking for sending the output of query to a file as the example in one of the automation thread shows. For me, the Select to File and Execute Script both look same with only difference where Select to File has option for export to 3 types of files. I tried that but only dumps one line of output where I’m expecting a quite a lot as my script has ton of select statements for which I’m looking for output (something like Oracle SQL command line where you can direct output of sql to a file)

---

<div class="post-metadata">

**Author:** ![PrashantGijare](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@PrashantGijare](https://forums.toadworld.com/u/PrashantGijare)\
**Post date:** [January 25, 2018, 6:45am UTC](https://forums.toadworld.com/t/automation/34818/6 "2018-01-25T06:45:41Z")

</div>

I think I finally found why my script output wasn’t sent to excel file. What I see that if my script has more than one sql statements, it only outputs the first one to the excel. In my case, I was looking for some count to perform an action so it created that one line output in excel which was bit non-intuitive to figure out what’s going on. When I tried other simple SQL statements, it worked perfectly but as soon as I add another statement, it ignored everything after first one. Hope this helps to recreate problem at your end and a solution

---

<div class="post-metadata">

**Author:** ![PrashantGijare](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@PrashantGijare](https://forums.toadworld.com/u/PrashantGijare)\
**Post date:** [March 15, 2018, 12:43pm UTC](https://forums.toadworld.com/t/automation/34818/7 "2018-03-15T12:43:31Z")

</div>

Hi Michael:

I was wondering if you or anyone got chance to look at this problem. Solution to this would really help many users to create output reports from multiple sql statements.

---

<div class="post-metadata">

**Author:** ![apitts](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@apitts](https://forums.toadworld.com/u/apitts)\
**Post date:** [March 15, 2018, 1:15pm UTC](https://forums.toadworld.com/t/automation/34818/8 "2018-03-15T13:15:10Z")

</div>

You will need to break your script into multiple export outputs. If you want them all to be in the same file, have them export to the same file (making sure that the overwrite option is unchecked in any subsequent exports after the first one). You can even name the tabs. Hope this helps.

---

<div class="post-metadata">

**Author:** ![PrashantGijare](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@PrashantGijare](https://forums.toadworld.com/u/PrashantGijare)\
**Post date:** [March 16, 2018, 8:26am UTC](https://forums.toadworld.com/t/automation/34818/9 "2018-03-16T08:26:12Z")

</div>

Thank you so much. This worked well although added a quite a lot of work to split into and then wire up a ton of sql files. Now that I’m able to do this, I was wondering if there is any option to loop through a folder and run scripts?

---

<div class="post-metadata">

**Author:** ![apitts](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@apitts](https://forums.toadworld.com/u/apitts)\
**Post date:** [March 16, 2018, 10:01am UTC](https://forums.toadworld.com/t/automation/34818/10 "2018-03-16T10:01:09Z")

</div>

Well. SQL rules still apply so you would have to write a C-based code section that loops through an external file system provided the SQL server and your file location “know” each other. Very, Very difficult and WAY above my pay grade. I wish I could help my friend but I’m just not that good. Perhaps someone on the boards could share some coding for both of us because that would be very interesting.
