Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 LF vs CRLF

Author  Topic 

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-19 : 16:32:45

Hello,

I'm trying to execute bulk insert from a text file (rrf if it matters) that was create on Linux system. The problem is that Linux uses LF as a line separator and Windows (as well as SQL) recognize CRLF (\n) as line separator (AKA "ROWTERMINATOR").

I was wondering if I can get SQL to recognize LF without editing the text file?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-19 : 16:41:18
CRLF is \r\n. CR is \r and LF is \n.

Use a hex editor to verify the row terminator.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-19 : 16:51:17

Hi Tara,

I did verify and it shows as LF, also, tried with '\r', '\r\n' and '\n\r' with no success. The only solution that worked was to edit the file and replace all '\n' with '\r\n', then (and only then) SQL allowed me to bulk insert with ROWTERMINATOR='\n' (why '\n' if it's '\r\n'?).

I did try:
  • ROWTERMINATOR ='\n'

  • ROWTERMINATOR ='\r'

  • ROWTERMINATOR ='\r\n'

  • ROWTERMINATOR ='\n\r'

on the original file with no success.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-19 : 19:41:04
How about via bcp.exe?

Here's an example:

bcp db1.dbo.t1 in C:\SomeFile.csv -Sserver1\instance1 -T -c -t, -r\n

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-24 : 16:48:53
Thanks but same like SQL Server Management Studio, no go.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-24 : 17:37:54
I've never run into this issue and I've certainly dealt with similar files. Are you service packed and hotfixed to at least sp3 CU4?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-24 : 18:29:59
Apparently not and currently with SP1. We're installing SP3 at the moment buy wont be able to restart the server 'till midnight. I'll keep you posted.

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-24 : 18:32:12
You also need to install it on the client machines since the service packs and hotfixes also update the client tools such as bcp.exe and SSMS.

I'd recommend also installing CU5 after SP3 since SP3 has many bugs in it that are fixed in the later cumulative update packages. We went with build 4262 since CU5 had just been released. SP3 only puts you at build 4035.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-24 : 20:31:09
Well, apparently SP3 restart SQL Server without any warnings, so it's there (and still no go). Then we installed CU4 but didn't restart the server since (yet). Should we restart before installing CU5 or go ahead with the new installation and restart once?

Current version is 9.00.4226.00.

I was wondering if I can send you the file to try on your system (it's a plain text file, about 220KB in size), if so, you can MP me your email address. I'll totally understand if you decline.

BTW, only one machine is involved so I guess I'm covered(?).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-24 : 22:39:34
The hotfixes (CUs) are cumulative, so you only needed to install CU5. It'll tell you at the end if a restart is required. Sometimes it is, sometimes it isn't.

I probably won't find time to work on it for about two weeks, but I'll send you my email in case it isn't urgent.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -