Solved

SQL Server Export table as text file on a schedule

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…

752 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