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

Answer Wiki

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

One option would be to create a stored procedure using <a href=”http://msdn.microsoft.com/en-us/library/ms175046(v=SQL.90).aspx”>xp_cmdshell</a> (which is disabled by default) to call <a href=”http://msdn.microsoft.com/en-us/library/ms162802.aspx”>bcp</a>, and schedule a task to execute it.

Something like this:

<pre>CREATE PROCEDURE yourProcedure AS
EXEC master..xp_cmdshell ‘bcp “SELECT * FROM yourDB.dbo.yourTable” queryout “c:\text.txt” -c -T’
GO</pre>

——————–

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Eabouzeid
    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?
    175 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following