SQL Server Agent Job - Export results to Tab Delim

2019-04-13 07:27发布

问题:

I setup a SQL server agent job that runs a stored procedure at a specific time. Once the stored procedure is done running, how can I export the results to a Tab Delimited file?

I'm using SQL Server 2008 R2.

Thanks

回答1:

If you have xp_cmdshell enabled and if your account has access you could try:

EXEC xp_cmdshell 'bcp "SELECT * FROM tblName" queryout "C:\tblNameData.txt" -T -c

Another way is to do it as @Neil mentioned: SSIS. Here's a link:

http://decipherinfosys.wordpress.com/2008/07/23/ssis-exporting-data-to-a-text-file-using-a-package/



回答2:

For this specific task, I would use SSIS, purely for its ease.

bcp is another alternative using a file format.