SQL Bulk Copy Export - Output to Export file, Tab delimiter

chokka
chokka used Ask the Experts™
on
Having a trouble on doing bulk copy export - I want to export a table data to text file output having tab as delimiter.

bcp "SELECT * FROM DatabaseLog" queryout TestingBulkCopy.txt -c -T

I am trying either on SQL 2008 or SQL 2012.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Topic Advisor, Page Editor
Distinguished Expert 2018
Commented:
Need to use "-t\t" as a parameter -t specifies the column delimiter and \t specifies the tab character
bcp "SELECT * FROM DatabaseLog" queryout "TestingBulkCopy.txt" -t\t -c -T 

Open in new window

And provide an output path as part of your output filename so you control where it goes...

Read https://docs.microsoft.com/en-us/sql/tools/bcp-utility
chokkaStudent

Author

Commented:
Thank you ...!!

When i tried by passing with the folder path - I am getting syntax error - I am running the query in SQL 2012

bcp "SELECT * FROM DatabaseLog" queryout "C:\TestingBulkCopy.txt" -t\t -c -T
Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018

Commented:
possibly dont have write access to the root of C:\  

try creating a folder first and if need be right click to go into properties / security and allow access.

what was the error ?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

chokkaStudent

Author

Commented:
Incorrect syntax near queryout - This has nothing to do with folder path permission
chokkaStudent

Author

Commented:
I tested the syntax in SQL 2012 and SQL 2008, I get incorrect syntax
Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018
Commented:
@chokka,

I am running it fine. Where and how are you running the BCP command ? Can you provide your code and details ?

T-SQL:
exec master..xp_cmdshell 'bcp "select * from testdb..yourtable" queryout "c:\test\ee\bcp_export_test.csv" -t\t -c -T'

Open in new window


And, what is the exact error message
Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018

Commented:
Hi Chokka,

Any more information to share ? Questions ? Error Messages ?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial