Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BCP question - any way to have a comma delimited, quoted columns?

4 views
Skip to first unread message

Eric

unread,
Dec 30, 2004, 2:34:22 PM12/30/04
to
I need a CSV output file with the columns themselves surrounded by quotes.
I've tried -c -t"," which gives me the commas, but have not yet found a
combo that gives me quoted values as well.
I also tried -c -t""" which gives me quotes but not commas except at the
beginning, and -c -t"","" didnt work, it just ignored the inner quotes and
used commas.
I need the quotes as sometimes there are commas inside the data itself.

I's like to see output like this:
" 123 1st Street", "Los Angeles," , "CA", "90001", "next column,
etc."

John Bell

unread,
Dec 30, 2004, 5:55:54 PM12/30/04
to
Hi

This is assuming that you want non-string fields enquoted? You can use
""",""" as the delimiter, but you are going to have problems with the quote
before the first field, therefore it may be easier to use a query to export
the data and include the delimiters where needed as literal strings.

John

"Eric" <er...@nospam.com> wrote in message
news:uqypUdq7...@TK2MSFTNGP10.phx.gbl...

Erland Sommarskog

unread,
Jan 1, 2005, 9:44:10 AM1/1/05
to

You will need to use a format file where you specify the delimiter for
each column. A sample:

8.0
7
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\",\"" 2 col2 ""
3 SQLCHAR 0 0 "\",\"" 3 col3 ""
4 SQLCHAR 0 0 "\"," 4 col4 ""
5 SQLCHAR 0 0 "," 5 col5 ""
6 SQLCHAR 0 0 "." 6 col6 ""
7 SQLCHAR 0 0 "\n" 0 "" ""

In this format file, the first column in the host file is an empty
field, which is only there to leave place for a " before the first
column. That's why there is a 0 in the sixth column.

This format file will enclose the three first columns in the file in
quotes, the last two will be unquoted. The last column will be terminated
by a period for some reason. (This was a file that I happened to have
lying on disk.)

Note also that the column names in the format file are informative only.
What matters is the column number in the sixth column.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

0 new messages