tob88
tob88

Reputation: 2211

Automated Export to CSV Using SQL Server Management Studio

Using Microsoft SQL Server Management Studio, I have created a view, which pulls in columns from several tables. I need to export this view into a CSV file on a weekly basis, and so I would like to set up some sort of automated process for this. I have read many examples of how I can do a simple right click and "Save Results As", or using the export wizard, but I do not know how I can automate this process to run weekly.

I am somewhat of a newbie with all things microsoft, so any help is much appreciated, thanks!

Upvotes: 2

Views: 53402

Answers (3)

Matten
Matten

Reputation: 17603

You can create an SSIS package (just google "sql server export data ssis") and execute it each week (you can create an automated task for this) or you can use xp's like demonstrated in this article.

Upvotes: 2

Denis Valeev
Denis Valeev

Reputation: 6015

It is also easy to setup a mailer that would mail a csv file as an attachment on a weekly basis using sp_send_dbmail command.

As a CSV attachment:

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'AdventureWorks2008R2 Administrator',
    @recipients = '[email protected]',
    @query = 'SELECT COUNT(*) FROM AdventureWorks2008R2.Production.WorkOrder
                  WHERE DueDate > ''2006-04-30''
                  AND  DATEDIFF(dd, ''2006-04-30'', DueDate) < 2' ,
    @subject = 'Work Order Count',
    @attach_query_result_as_file = 1 ;

Source: http://msdn.microsoft.com/en-us/library/ms190307.aspx

Upvotes: 4

Kaf
Kaf

Reputation: 33839

What you need is to schedule a job to run every week. Please have a look at here http://msdn.microsoft.com/en-us/library/ms191439.aspx

Upvotes: 2

Related Questions