Reputation: 117
I want to export my query result to .txt or .csv file but using command.
I want to do something like this:
BULK "EXPORT" (Select * from MyTable) to 'C:\Users\admin\Desktop\filename.txt' WITH (FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n')
How can i do this?
Upvotes: 0
Views: 2724
Reputation: 1370
I have used below statement to export tab separated data in csv
mysql -h$ip -u$user -p$password -P3310 $dbName -B -e "select * from a" > a_data.csv
Upvotes: 0
Reputation: 623
Use SQLCMD as below -
sqlcmd -S . -d DbName -E -s',' -W -Q "SELECT * FROM [Table]" > C:\Test.csv
You can also try BCP as below -
bcp [BookDb].[dbo].[Books] out C:\Test1.csv -T
Follow below link for more information - https://www.red-gate.com/simple-talk/sql/database-administration/working-with-the-bcp-command-line-utility/
Upvotes: 3