## Automate TSQL Query Output

175 pts.
Tags:
SQL
SQL Query
T-SQL
I want to have a stored procedure run on a schedule that automatically creates a database output file as a result and saves it to a specific location on my network. Can someone please tell me how to do this?

Software/Hardware used:
SQL Server 2005

Thanks. We'll let you know when a new response is added.

One option would be to create a stored procedure using xp_cmdshell (which is disabled by default) to call bcp, and schedule a task to execute it.

Something like this:

CREATE PROCEDURE yourProcedure AS
EXEC master..xp_cmdshell 'bcp "SELECT * FROM yourDB.dbo.yourTable" queryout "c:\text.txt" -c -T'
GO

——————–