Reputation: 5759
How would I output to a text file to the user's hard drive from SQL Server 2008? In the scenario the user's hard drive is the same hard drive containing the SQL Server.
I don't want the output to be a .csv file or an xml file, just plain text. I also need to do this in the code. I don't want the user to have to manually click export or another GUI button everytime. My plan is to include this functionality in a stored procedure.
Upvotes: 2
Views: 3191
Reputation: 21
Maybe try a BCP out? http://msdn.microsoft.com/en-us/library/ms162802.aspx
Might have an issue getting it directly to the users hard drive depending on the network setup. It might be worth a shot.
bcp TABLENAME out FILEPATH OPTIONS
Upvotes: 1
Reputation: 280262
You forgot to mention which version of SQL Server you're using, but assuming SQL Server 2005 or better, I would use SQLCLR for this, not xp_cmdshell or sp_OACreate. See the earliest answer to this question.
Upvotes: 4