Solved

SQL Server Export table as text file on a schedule

Posted on 2013-01-24
2
365 Views
Last Modified: 2013-01-27
I think this is relatively easy, but I have been unable to find what I'm looking for. Is there an example of creating a job that will export a table to a file location on a regular basis (weekly)? I'm using SQL Server 2008. Thanks for any help.
0
Comment
Question by:dodgerfan
  • 2
2 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 38816169
something like that

xp_cmdshell 'bcp "SELECT * FROM MyTable" queryout "C:\MyTable.txt" -T -c -t

To schedule export you can create a scheduled job on SQL Server side
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 38816189
so

step 1:

create a stored procedure with the following content:

DECLARE @sql varchar(8000)

SELECT @sql = 'bcp "select * from MyTable" queryout c:\MyTable.txt -c -t, -T -S <servername>' 

EXEC master..xp_cmdshell @sql

Open in new window


step 2:
create a scheduled job that runs this stored procedure
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question