Thanks For all your help and support, Today again i am stuck in a problem .
I have to create a job which execute some SQL Script and i want to copy that result on Excel or Text file and then want to sent that file as attachemnt to my Client.
asked May 30 '12 at 10:40 AM in Default
You can use OPENROWSET to export the data to Excel
The pre-requisites for this are
Then you can use database mail to send this file as an attachment using SQL Agent Job. See sp_send_dbmail for help.
You don't mention what version of SQL Server you are using, thus I'm assuming 2005 or higher.
Just throwing this out there, you can also use the 'Export Wizard' to generate a simple package that you can then run as a job to export the data. You would then need to modify the package to include the email step in order to email the file to the recipient. Assuming that the file name doesn't change as well as the email recipient, this can be easily done in BIDS.
Even if either of those two variables need to be generated dynamically, this can be done as well with a little bit of tweaking to the package.
To start this, just right-click on the database and select Tasks-->Export Data. This will start a wizard and take you through the process of generating the SSIS package. The wizard will also allow you to schedule the package to run as a job.
I know that you stated you wanted a SQL Script to execute, however I just wanted to point out another possible solution so that you had a couple to choose from.
Hope this helps!