dbTalk Databases Forums  

What is the proper row terminator if rows are terminated with hex

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss What is the proper row terminator if rows are terminated with hex in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Snake
 
Posts: n/a

Default What is the proper row terminator if rows are terminated with hex - 10-02-2009 , 01:18 PM






I have a text file whos rows are terminated with 0A (NewLine). When I try to
bcp IN these rows using -r"\n" which is the NewLine character it yields a
"right truncation" error. When I recreate the file with 0D0A, the file loads
properly, even though I use the same -r parameter. It seems bcp requires the
0D (Carriage Return) even though it is not specified in the -r parameter. I
have tested this thoroughly and it indeed does behave this way on SS2000. So
how do I get the file to load when terminated with only the 0A?

Thanks

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: What is the proper row terminator if rows are terminated with hex - 10-02-2009 , 04:28 PM






Snake (Snake (AT) discussions (DOT) microsoft.com) writes:
Quote:
I have a text file whos rows are terminated with 0A (NewLine). When I
try to bcp IN these rows using -r"\n" which is the NewLine character it
yields a "right truncation" error. When I recreate the file with 0D0A,
the file loads properly, even though I use the same -r parameter. It
seems bcp requires the 0D (Carriage Return) even though it is not
specified in the -r parameter. I have tested this thoroughly and it
indeed does behave this way on SS2000. So how do I get the file to load
when terminated with only the 0A?
You need to use a format file. In a format file, \n means \n and not
\r\n.

Say that your file is tab-separated with four fields, equally many as
in your target table. Then your format file should look like this:

8.0
4
1 SQLCHAR 0 0 "\t" 1 col1 ""
2 SQLCHAR 0 0 "\t" 2 col2 ""
3 SQLCHAR 0 0 "\t" 3 col3 ""
4 SQLCHAR 0 0 "\n" 4 col4 ""




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.