Solved

SQL Server Export table as text file on a schedule

Posted on 2013-01-24
2
370 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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