Showing posts with label newline. Show all posts
Showing posts with label newline. Show all posts

Sunday, March 25, 2012

Bulk Insert with mid-string newlines

Hi.
I have a text file with several fields. One of these sometimes contains
newline characters. Any fields that do include newline characters are
enclosed with double quotes. What Bulk Insert command line do I need to use
to impot the file without it treating the enclosed newline characters as end
of row delimiters?
Example:
a,b,"c/nld",e
becomes
a b c
d e
where it should be
a b c/nd e
Thanks in advance,
Neil JonesTo clarify, I am looking for a commandline paramter that allows me to
designate a string delimiter, so that everything within the delimiters is
treated as a single string.
"NeilDJones" wrote:

> Hi.
> I have a text file with several fields. One of these sometimes contains
> newline characters. Any fields that do include newline characters are
> enclosed with double quotes. What Bulk Insert command line do I need to us
e
> to impot the file without it treating the enclosed newline characters as e
nd
> of row delimiters?
> Example:
> a,b,"c/nld",e
> becomes
> a b c
> d e
> where it should be
> a b c/nd e
> Thanks in advance,
> Neil Jones|||If you have custom formating, you'd want to use format file.
http://msdn.microsoft.com/library/e...pt_bcp_9yat.asp
-oj
"NeilDJones" <NeilDJones@.discussions.microsoft.com> wrote in message
news:8EBC7227-CD12-4450-93E1-F94E4D5621C6@.microsoft.com...
> Hi.
> I have a text file with several fields. One of these sometimes contains
> newline characters. Any fields that do include newline characters are
> enclosed with double quotes. What Bulk Insert command line do I need to
> use
> to impot the file without it treating the enclosed newline characters as
> end
> of row delimiters?
> Example:
> a,b,"c/nld",e
> becomes
> a b c
> d e
> where it should be
> a b c/nd e
> Thanks in advance,
> Neil Jones|||Thanks for the reply.
Looking at the information for the format file, I still cannot see how I
specify string delimiters, as I am able to do in Excel or Access. Is this
just something that BULK INSERT doesn't handle properly?
Cheers,
Neil
"oj" wrote:

> If you have custom formating, you'd want to use format file.
> http://msdn.microsoft.com/library/e...pt_bcp_9yat.asp
>
>
> --
> -oj
>
> "NeilDJones" <NeilDJones@.discussions.microsoft.com> wrote in message
> news:8EBC7227-CD12-4450-93E1-F94E4D5621C6@.microsoft.com...
>
>|||Sorry for the late reply.
With bulk load (bcp/bulk insert), you can define the column and row
delimiter. However, each must be different from each other (i.e. not
possible when column and row delimiter is defined as \r\n).
If excel/access can format it correctly for you, you might want to send the
data through it first before importing into sqlserver.
-oj
"NeilDJones" <NeilDJones@.discussions.microsoft.com> wrote in message
news:DE2EC0CB-E11F-4DC5-9496-D03482518603@.microsoft.com...
> Thanks for the reply.
> Looking at the information for the format file, I still cannot see how I
> specify string delimiters, as I am able to do in Excel or Access. Is this
> just something that BULK INSERT doesn't handle properly?
> Cheers,
> Neil
> "oj" wrote:
>|||Thanks.
I think I am puttnig this badly.
There is no problem with row or column delimiters. The column delimiter is a
comma, and the row delimiter is newline.
Some of the columns are strings, and these may or may not contain double
quotes ("). If there are double quotes, then everything inside the quotes is
a single string.
The problem arises when there is a newline character within the double
quote-delimited string, eg "Hello\nWorld", which is the string representing
Hello
World
Ideally, this would import as a single string. Excel and Access both do this
fine, but bulk insert doesn't recognise the string delimiter ", and breaks
the string over two lines.
I am hoping someone out there knows how to specify a string delimiter, but
am thinking that there ain't one.
Cheers,
Neil
"oj" wrote:

> Sorry for the late reply.
> With bulk load (bcp/bulk insert), you can define the column and row
> delimiter. However, each must be different from each other (i.e. not
> possible when column and row delimiter is defined as \r\n).
> If excel/access can format it correctly for you, you might want to send th
e
> data through it first before importing into sqlserver.
> --
> -oj
>
> "NeilDJones" <NeilDJones@.discussions.microsoft.com> wrote in message
> news:DE2EC0CB-E11F-4DC5-9496-D03482518603@.microsoft.com...
>
>

BULK INSERT with leading/trailing quotes

I am using BULK INSERT to load data from some CSV-file into SQL-server 7.0.
The files use TAB to seperate fields and NEWLINE to seperate rows.
However - we would like to be able to have these characters in the fields
themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
the users.
The standard way to do this is to enclose the fields in e.g. double quotes
'"' and escape any double quotes within these fields, so that the CSV-row
JESPER STOC"HOLM
becomes
"JESPER" "STOC""HOLM"
However, BULK INSERT doesn't seem to support this.
Can you guys confirm this?
I have looked at the option to use a FORMATFILE from BCP, but is seems that
these files are table-specific, meaning that as we need to upload to 315+
tables, we need 315+ format files.
Is it possible to create a standard FORMAT file that only contains
information about the trailing/leading double quotes and how to interpret
the escaped quotes? This file should be used for all tables.
Before I dig even further down into the doc (BOL), can you guys also
confirm this?
Thanks,
:o)
Jesper Stocholm
http://stocholm.dkJesper Stocholm (j@.stocholm.invalid) writes:
> However - we would like to be able to have these characters in the fields
> themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
> the users.
> The standard way to do this is to enclose the fields in e.g. double quotes
> '"' and escape any double quotes within these fields, so that the CSV-row
> JESPER STOC"HOLM
> becomes
> "JESPER" "STOC""HOLM"
> However, BULK INSERT doesn't seem to support this.
Yes and no. You can sort it out with a format file, STOC""HOLM would
remain STOC""HOLM.

> I have looked at the option to use a FORMATFILE from BCP, but is seems
> that these files are table-specific, meaning that as we need to upload
> to 315+ tables, we need 315+ format files.
That is correct. There is no built in generic mechanism to handle what
you ask for. You would have to write a program that generates the format
files. Or a program that reads the import file, and then feeds it to BCP.
You may want to look at DTS and the import wizard, and see what it offers.
I have not used DTS myself, though, so I am not able to answer any questions
for it.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspxsql

BULK INSERT with leading/trailing quotes

I am using BULK INSERT to load data from some CSV-file into SQL-server 7.0.
The files use TAB to seperate fields and NEWLINE to seperate rows.
However - we would like to be able to have these characters in the fields
themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
the users.
The standard way to do this is to enclose the fields in e.g. double quotes
'"' and escape any double quotes within these fields, so that the CSV-row
JESPER STOC"HOLM
becomes
"JESPER" "STOC""HOLM"
However, BULK INSERT doesn't seem to support this.
Can you guys confirm this?
I have looked at the option to use a FORMATFILE from BCP, but is seems that
these files are table-specific, meaning that as we need to upload to 315+
tables, we need 315+ format files.
Is it possible to create a standard FORMAT file that only contains
information about the trailing/leading double quotes and how to interpret
the escaped quotes? This file should be used for all tables.
Before I dig even further down into the doc (BOL), can you guys also
confirm this?
Thanks,
:o)
Jesper Stocholm
http://stocholm.dk
Jesper Stocholm (j@.stocholm.invalid) writes:
> However - we would like to be able to have these characters in the fields
> themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
> the users.
> The standard way to do this is to enclose the fields in e.g. double quotes
> '"' and escape any double quotes within these fields, so that the CSV-row
> JESPER STOC"HOLM
> becomes
> "JESPER" "STOC""HOLM"
> However, BULK INSERT doesn't seem to support this.
Yes and no. You can sort it out with a format file, STOC""HOLM would
remain STOC""HOLM.

> I have looked at the option to use a FORMATFILE from BCP, but is seems
> that these files are table-specific, meaning that as we need to upload
> to 315+ tables, we need 315+ format files.
That is correct. There is no built in generic mechanism to handle what
you ask for. You would have to write a program that generates the format
files. Or a program that reads the import file, and then feeds it to BCP.
You may want to look at DTS and the import wizard, and see what it offers.
I have not used DTS myself, though, so I am not able to answer any questions
for it.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

BULK INSERT with leading/trailing quotes

I am using BULK INSERT to load data from some CSV-file into SQL-server 7.0.
The files use TAB to seperate fields and NEWLINE to seperate rows.
However - we would like to be able to have these characters in the fields
themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
the users.
The standard way to do this is to enclose the fields in e.g. double quotes
'"' and escape any double quotes within these fields, so that the CSV-row
JESPER STOC"HOLM
becomes
"JESPER" "STOC""HOLM"
However, BULK INSERT doesn't seem to support this.
Can you guys confirm this?
I have looked at the option to use a FORMATFILE from BCP, but is seems that
these files are table-specific, meaning that as we need to upload to 315+
tables, we need 315+ format files.
Is it possible to create a standard FORMAT file that only contains
information about the trailing/leading double quotes and how to interpret
the escaped quotes? This file should be used for all tables.
Before I dig even further down into the doc (BOL), can you guys also
confirm this?
Thanks,
:o)
Jesper Stocholm
http://stocholm.dkJesper Stocholm (j@.stocholm.invalid) writes:
> However - we would like to be able to have these characters in the fields
> themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
> the users.
> The standard way to do this is to enclose the fields in e.g. double quotes
> '"' and escape any double quotes within these fields, so that the CSV-row
> JESPER STOC"HOLM
> becomes
> "JESPER" "STOC""HOLM"
> However, BULK INSERT doesn't seem to support this.
Yes and no. You can sort it out with a format file, STOC""HOLM would
remain STOC""HOLM.

> I have looked at the option to use a FORMATFILE from BCP, but is seems
> that these files are table-specific, meaning that as we need to upload
> to 315+ tables, we need 315+ format files.
That is correct. There is no built in generic mechanism to handle what
you ask for. You would have to write a program that generates the format
files. Or a program that reads the import file, and then feeds it to BCP.
You may want to look at DTS and the import wizard, and see what it offers.
I have not used DTS myself, though, so I am not able to answer any questions
for it.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

BULK INSERT with leading/trailing quotes

I am using BULK INSERT to load data from some CSV-file into SQL-server 7.0.
The files use TAB to seperate fields and NEWLINE to seperate rows.
However - we would like to be able to have these characters in the fields
themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
the users.
The standard way to do this is to enclose the fields in e.g. double quotes
'"' and escape any double quotes within these fields, so that the CSV-row
JESPER STOC"HOLM
becomes
"JESPER" "STOC""HOLM"
However, BULK INSERT doesn't seem to support this.
Can you guys confirm this?
I have looked at the option to use a FORMATFILE from BCP, but is seems that
these files are table-specific, meaning that as we need to upload to 315+
tables, we need 315+ format files.
Is it possible to create a standard FORMAT file that only contains
information about the trailing/leading double quotes and how to interpret
the escaped quotes? This file should be used for all tables.
Before I dig even further down into the doc (BOL), can you guys also
confirm this?
Thanks,
:o)
--
Jesper Stocholm
http://stocholm.dkJesper Stocholm (j@.stocholm.invalid) writes:
> However - we would like to be able to have these characters in the fields
> themselves, e.g. a TAB or NEWLINE in a field which contain free-text from
> the users.
> The standard way to do this is to enclose the fields in e.g. double quotes
> '"' and escape any double quotes within these fields, so that the CSV-row
> JESPER STOC"HOLM
> becomes
> "JESPER" "STOC""HOLM"
> However, BULK INSERT doesn't seem to support this.
Yes and no. You can sort it out with a format file, STOC""HOLM would
remain STOC""HOLM.
> I have looked at the option to use a FORMATFILE from BCP, but is seems
> that these files are table-specific, meaning that as we need to upload
> to 315+ tables, we need 315+ format files.
That is correct. There is no built in generic mechanism to handle what
you ask for. You would have to write a program that generates the format
files. Or a program that reads the import file, and then feeds it to BCP.
You may want to look at DTS and the import wizard, and see what it offers.
I have not used DTS myself, though, so I am not able to answer any questions
for it.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx