Thanks,If it's just a line feed (hex 0A), then you should be able to use '\l\' as the rowterminator. (Note that is a lowercase "L".)
Terri|||Ryan..did that work for you?
Thanks,If it's just a line feed (hex 0A), then you should be able to use '\l\' as the rowterminator. (Note that is a lowercase "L".)
Terri|||Ryan..did that work for you?
Any suggestions on what I should use as the row terminator? Is it
possible to tell BULK INSERT to use something like "CHAR(10)\n"?
"\n\n" does NOT work.
Thanks in advance.I found it!
"\r\n" works like a charm.. "\r" is for carriage return only.. I'm
surprised I didn't already know that.
I found the answer here:
http://www4.dogus.edu.tr/bim/bil_ka...l65dba/ch16.htm
under table:
Table 16.4. Valid field terminators.
Terminator Type Syntax
tab \t
new line \n
carriage return \r
backslash \\
NULL terminator \0
user-defined terminator character (^, %, *, and so on)sql
I don't believe that you will be able to use multiple terminitors.
The way that I have dealth with issues like this is to create a 'data washing' step prior to the bulk load. If you are using a JOB, DTS, or SSIS, create a step that runs a small batch file that pre-processes the data, changing whatever characters to what other characters are needed, and then move on to the bulk load step.
You will need to use a format file, in this you can specify the terminator for the last column in a row.
Have a look in BOL. This page shows an example of a file using /r/n which you can obviously change
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/ecfc546d-f708-45f4-878d-fb71b5fd1a0a.htm
|||Of if you are using the BULK INSERT TSQL statement look at this page
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/be3984e1-5ab3-4226-a539-a9f58e1e01e2.htm
|||I figured out that the problem has to do with MSSQL's native behavior. It turns out that whenever it sees \n, it automatically converts it to \r\n, without notifiying the user. There are at least three ways to work around this strange behavior: 1) replace every \n in your file with \r\n before using Bulk Insert, 2) build your sql statement dynamically either in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +, instead of '\n' as the line terminator in your statement, and 3) load your file into a Datatable via ADO.net, and then insert the entire Datatable into MSSQL.|||Note sure what figuring out was required, as BOL has an example that just works.
|||I have never succeeded to convince BULK INSERT to read Unix
files, and I find one of these solutions usually works:
1. See if the process that moved the files from the Unix
machine can correct the line ends (for example, ftp can do
this)
2. Run the Unix utility unix2dos on the files before they
leave the Unix machine, or afterwards, under the Cygwin
Unix shell for Windows. (Or write a tiny command-line
Windows program to do this.)
Steve Kass
Drew University
ktto@.discussions.microsoft.com wrote:
> I figured out that the problem has to do with MSSQL's native behavior.
> It turns out that whenever it sees \n, it automatically converts it to
> \r\n, without notifiying the user. There are at least three ways to work
> around this strange behavior: 1) replace every \n in your file with \r\n
> before using Bulk Insert, 2) build your sql statement dynamically either
> in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +,
> instead of '\n' as the line terminator in your statement, and 3) load
> your file into a Datatable via ADO.net, and then insert the entire
> Datatable into MSSQL.
>
You will need to use a format file, in this you can specify the terminator for the last column in a row.
Have a look in BOL. This page shows an example of a file using /r/n which you can obviously change
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/ecfc546d-f708-45f4-878d-fb71b5fd1a0a.htm
|||Of if you are using the BULK INSERT TSQL statement look at this page
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/be3984e1-5ab3-4226-a539-a9f58e1e01e2.htm
|||I figured out that the problem has to do with MSSQL's native behavior. It turns out that whenever it sees \n, it automatically converts it to \r\n, without notifiying the user. There are at least three ways to work around this strange behavior: 1) replace every \n in your file with \r\n before using Bulk Insert, 2) build your sql statement dynamically either in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +, instead of '\n' as the line terminator in your statement, and 3) load your file into a Datatable via ADO.net, and then insert the entire Datatable into MSSQL.|||Note sure what figuring out was required, as BOL has an example that just works.
|||I have never succeeded to convince BULK INSERT to read Unix
files, and I find one of these solutions usually works:
1. See if the process that moved the files from the Unix
machine can correct the line ends (for example, ftp can do
this)
2. Run the Unix utility unix2dos on the files before they
leave the Unix machine, or afterwards, under the Cygwin
Unix shell for Windows. (Or write a tiny command-line
Windows program to do this.)
Steve Kass
Drew University
ktto@.discussions.microsoft.com wrote:
> I figured out that the problem has to do with MSSQL's native behavior.
> It turns out that whenever it sees \n, it automatically converts it to
> \r\n, without notifiying the user. There are at least three ways to work
> around this strange behavior: 1) replace every \n in your file with \r\n
> before using Bulk Insert, 2) build your sql statement dynamically either
> in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +,
> instead of '\n' as the line terminator in your statement, and 3) load
> your file into a Datatable via ADO.net, and then insert the entire
> Datatable into MSSQL.
>
Hi,
I have a set of records in application memory seperated by a record terminator '\n'. I can write the memory stream to a local disk file and call bcp api functions to load the file in to SQL server. But how do I transfer the in memory data directly to the SQL server, without writing to a data file, using ODBC. I am not using any .Net Framework classes in my code. The SQL server and application server(generating the data records) are on two different physical servers connected through network. I am trying to figureout the fastest and efficient way to load the data to SQL server from a remote application server. Thanks for your help.
Srini
Hi Srini,
You need to use the In-Memory BCP APIs for this purpose. You can look up the MSDN documentation for bcp_bind function which also has a small sample code about how to do it. Here is a link:
http://msdn2.microsoft.com/ru-ru/library/ms131401.aspx
Thanks
Waseem
build sql script,sql