Solved

SQL Server Export table as text file on a schedule

Posted on 2013-01-24
2
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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