Solved

SQL Server Export table as text file on a schedule

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sql Query Lookup based on range 2 30
how to import 7 54
Distinct values from two tables 14 20
Square brackets 4 12
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the fileā€¦

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now