## 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

——————–

## Discuss This Question: 1 Reply

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
• Thank you Carlos. Are there any other options? This option is disabled at my company. Is there an option to do this another way that might work?