Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OUTFILE Microsoft SQL Server equivalent?

Tags:

sql

sql-server

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

like image 552
Melvin Smiley Avatar asked Oct 27 '25 12:10

Melvin Smiley


2 Answers

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:

  • Code Samples
  • BCP Utility Reference
  • xp_cmdshell Reference
like image 105
Brian Webster Avatar answered Oct 30 '25 01:10

Brian Webster


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.

like image 32
KMC Avatar answered Oct 30 '25 03:10

KMC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!