0

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?

3
  • There is no BULK EXPORT, only BULK INSERT. Is bcp an option? Commented Dec 21, 2018 at 18:19
  • Im trying to apply bcp, but i dont know how Commented Dec 21, 2018 at 18:22
  • why not sqlcmd? Commented Dec 21, 2018 at 18:43

2 Answers 2

3

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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

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.