Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

BCP Utility Comma

$
0
0
I have the following problem. I need to create a .csv file with SQL (with the bcp utility). I can create this .csv file and the following data is inserted:
1","ad","dsa","333","","2","0","","","","""

I want to avoid this double quotes. I want only double quotes if there is a comma in one field. For better understanding, the following 3 cases must be done.

Fields containin commas can be surounded by quotation marks, these must be double quotation marks (“ ”) and not single (‘ ’) e.g.

“a, b, c” would be accepted as 1 single field but a, b, c would be 3 separate fields.

In adition, any double quotation marks which need to be displayed in a field must also be surounded by double quotation marks e.g.

If an address should display as “The Street”, this should be sent as ““The Street””

Apostrophes can be sent in the file e.g.
A client with surname O’Clay and forename Jenny with a free text field holding “comma, example” would be sent in the file as O’Clay,Jenny,”comma,example”.


This is my code:
bcp TESTPROJECT.dbo.table out c:\aa.txt -c -t"\",\"" -r"\"\n\"" -S .\sql2014 -U username -P password

So the problem is in the -t"\",\"" -r"\"\n\"" part but how I can do this?

Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>