3

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?

2
  • I would recommend checking out this link: thiagsundar.wordpress.com/export-data-to-text-file It shows a great way to export data to a text file from SQL Server. Commented Jul 15, 2012 at 3:55
  • Any language being used like c# ? Commented Jul 15, 2012 at 6:29

1 Answer 1

1

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:

  1. BCP
  2. SSIS
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.