简体   繁体   English

使用SQL Server 2008自动生成文本文件

[英]Generating a text file automatically using SQL Server 2008

I want to execute a Stored procedure in SQL Server 2008 and store the data in a text file. 我想在SQL Server 2008中执行存储过程并将数据存储在文本文件中。 How to do this and how to generate a text file automatically with data in SQL Server 2008? 如何执行此操作以及如何使用SQL Server 2008中的数据自动生成文本文件?

One of the method is to make use of BCP (Bulk Copy Program) to do this. 其中一种方法是使用BCP(批量复制程序)来执行此操作。 You need to have xp_cmdshell enabled to get this working. 您需要启用xp_cmdshell才能使其正常工作。

Also you can also make use of SSIS Import/Export wizard to achieve this. 您还可以使用SSIS导入/导出向导来实现此目的。

EXEC master..xp_cmdshell 'BCP "exec dbname.schemaname.procname" queryout "C:\outputfile.txt" -T -c -t,'

Check out these: 看看这些:

  1. BCP BCP
  2. SSIS SSIS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM