0

I have a simple BCP command to query my MSSQL database and copy the result to a .csv file like this:

bcp "select fullname from [database1].[dbo].employee" queryout  "c:\test\table.csv"  -c -t"," -r"\n" -S servername -T

The issue comes when the fullname column is varchar separated by a comma like "Lee, Bruce". When the result is copied to the .csv file, the portion before the comma (Lee) is placed into the first column in Excel spreadsheet and the portion after the comma (Bruce) is placed in the second column. I would like it to keep everything in the first column and keep the comma (Lee, Bruce) . Does anyone have any idea how to achieve this?

1 Answer 1

2

Obviously you should set columns separator to something different than comma. I'm not familiar with the above syntax, but I guess these: -c -t"," -r"\n" are column and new line separators respectively.

Further you should either change default CSV separator in regional settings OR use import wizard for proper data placing in Excel. By the way, there are plenty of similar questions on SO.

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

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.