4

Is there something like INTO...OUTFILE (from MySQL) in Microsoft SQL Server?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Melvin Smiley
  • 109
  • 2
  • 2
  • 8
  • What are you trying to achieve (apart from getting some data out of your database and on to disk)? Your question is rather lacking detail, if you explain *why* you want this functionality it might help others answer you question. SQL Server has SSIS (DTS depending on earlier versions) to export data, will that not do what you want? – Tony Jun 17 '11 at 20:30
  • I was thinking the same thing here- DTS. Didn't want to provide that answer though because the question left so much without explanation... – Mike Veigel Jun 17 '11 at 20:31

3 Answers3

4

This code causes the query results to be dumped into a text file.

EXEC master..xp_cmdshell'bcp "SELECT TOP 5 CUSTOMERID FROM Northwind.dbo.Customers" queryout "c:\text.txt" -c -T -x'

References:

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
2

You can also use the sqlcmd or osql (in SQL 2000) to store the output from a command line outside of SSMS very like working with mysql from the command line. You just have to provide the correct parameters, including the query you want to run.

KMC
  • 31
  • 1
  • 4
1

It depends on how fancy you want to get. You can use SSMS to generate a CSV A less user-friendly option is a BCP export. Which I see @hamlin11 just suggested

Community
  • 1
  • 1
billinkc
  • 59,250
  • 9
  • 102
  • 159