Wednesday, March 21, 2012

Quotes In BCP

I'm exporting via BCP. I'd like to have quotes around the text values. In
DTS, you have the text qualifier option. Is there a BCP option that
corresponds to the DTS option known as the Text Qualifier?
"SR" <mv2k_2003-news@.yahoo.com> wrote in message
news:7L9mc.5460$1T4.3283@.newssvr27.news.prodigy.co m...
> I'm exporting via BCP. I'd like to have quotes around the text values. In
> DTS, you have the text qualifier option. Is there a BCP option that
> corresponds to the DTS option known as the Text Qualifier?
>
In checking the BCP options, I could not find one that corresponds to DTS...
Steve
|||I cannot find a BCP way to do what you ask. You cannot make a " be the
field terminator. What you can do is still create a DTS package and run it
from the DTSRUN utility if you needed it to be command line.
Jeff Duncan
MCDBA, MCSE+I
"Steve Thompson" <SteveThompson@.nomail.please> wrote in message
news:eSZSddtMEHA.2468@.TK2MSFTNGP11.phx.gbl...[vbcol=seagreen]
> "SR" <mv2k_2003-news@.yahoo.com> wrote in message
> news:7L9mc.5460$1T4.3283@.newssvr27.news.prodigy.co m...
In
> In checking the BCP options, I could not find one that corresponds to
DTS...
> Steve
>
|||Yeah I knew about the DTS option. Thanks for the help everybody.
"Jeff Duncan" <jduncan@.gtefcu.org> wrote in message
news:%23hpg0CuMEHA.936@.TK2MSFTNGP11.phx.gbl...
> I cannot find a BCP way to do what you ask. You cannot make a " be the
> field terminator. What you can do is still create a DTS package and run
it
> from the DTSRUN utility if you needed it to be command line.
> --
> Jeff Duncan
> MCDBA, MCSE+I
> "Steve Thompson" <SteveThompson@.nomail.please> wrote in message
> news:eSZSddtMEHA.2468@.TK2MSFTNGP11.phx.gbl...
> In
> DTS...
>
|||SR,

> I'm exporting via BCP. I'd like to have quotes around the text
> values. In DTS, you have the text qualifier option. Is there a
> BCP option that corresponds to the DTS option known as the Text
> Qualifier?
You need to use a format file for this. Using the pubs..authors
table as an example, we'll bcp out of a view that looks like this:
use pubs
go
create view authors_csv as
select null first_quote, * from authors
Note that we are including a dummy column called first_quote
that just returns NULL. It's just a little trick to get the leading
quote on the first column.
The format file looks like this:
8.0
10
1 SQLCHAR 0 0 "\"" 1 first_quote ""
2 SQLCHAR 0 11 "\",\"" 2 au_id ""
3 SQLCHAR 0 40 "\",\"" 3 au_lname ""
4 SQLCHAR 0 20 "\",\"" 4 au_fname ""
5 SQLCHAR 0 12 "\",\"" 5 phone ""
6 SQLCHAR 0 40 "\",\"" 6 address ""
7 SQLCHAR 0 20 "\",\"" 7 city ""
8 SQLCHAR 0 2 "\",\"" 8 state ""
9 SQLCHAR 0 5 "\",\"" 9 zip ""
10 SQLCHAR 0 1 "\"\r\n" 10 contract ""
That dummy column is also in the format file to get the leading
quote on au_id.
Here's the command line:
bcp pubs..authors_csv out authors_csv.dat -fauthors_csv.bcp -S. -T
Linda

No comments:

Post a Comment