I want to execute a Stored procedure in SQL Server 2008 and store the data in a text file. How to do this and how to generate a text file automatically with data in SQL Server 2008?
One of the method is to make use of BCP (Bulk Copy Program) to do this. You need to have xp_cmdshell enabled to get this working.
Also you can also make use of SSIS Import/Export wizard to achieve this.
EXEC master..xp_cmdshell 'BCP "exec dbname.schemaname.procname" queryout "C:\outputfile.txt" -T -c -t,'
Check out these:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With