Once upon a time, I’m ordered by client to create application / script to generate all stored procedures for versioning purpose. Before, I only know to generate all stored procedure using SSMS tools into one file, so, almost every versioning there are many conflicts found and it’s really difficult to trace back script. (actually there are 2 options in “generate script” SSMS, into one file or each stored procedures to file :)
because of that, I found something interesting, BCP Utility. This tools provided by SQL Server that can do bulk copies from SQL Server to data file. Easily, this tools can be used to export query result to file (I only try to export to TXT).
Here example for BCP :
[code language=”sql”]xp_cmdshell ‘bcp "select top 100 * from AdventureWorks.Person.Address" queryout C:UsersMarifnstDesktoparif.txt -T -c'[/code]
and explanation for arguments (source : http://msdn.microsoft.com/en-us/library/ms162802.aspx) :
- -T : Specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security.
- -c : Performs the operation using a character data type.
Note : I hope you have known about xp_cmdshell.
I hope this help.