Solved

Bulk insert

Posted on 2002-07-02
5
1,476 Views
Last Modified: 2009-04-07
Hi,

I need to load a file of which the row terminator is only a linefeed (0A). How can I load this file? BULK INSERT only has \n (0D0A) and \r (0D) as row terminators. If you use \n, BULK INSERT od BCP always add the 0D.

tnx.
0
Comment
Question by:erde
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7124074
see this article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_impt_bcp_0fqq.asp
<...>
When you use bcp interactively and specify \n (newline) as the row terminator, bcp prefixes the \r (carriage return) character automatically.
<...>

I suggest that you specify the parameters using -f<formatfile> options:

-f format_file

Specifies the full path of the format file that contains stored responses from a previous use of bcp on the same table or view. Use this option when using a format file created with the format option to bulk copy data in or out. Creation of the format file is optional. After prompting you with format questions, bcp prompts whether to save the answers in a format file. The default file name is Bcp.fmt. bcp can refer to a format file when bulk copying data; therefore, reentering previous format responses interactively is not necessary. If this option is not used and -n, -c, -w, -6, or -N is not specified, bcp prompts for format information


CHeers
0
 
LVL 1

Accepted Solution

by:
dewpat earned 50 total points
ID: 7124164
You can create a command with the LF included :

declare @command varchar(1000)
declare @lf char(1)
select @lf=char(10)
select @command='
BULK INSERT test
   FROM ''d:\temp\testfile''
   WITH
     (
        FIELDTERMINATOR = ''\t'',
        ROWTERMINATOR = '''+@lf+'''
      )'
exec (@command)

0
 
LVL 2

Author Comment

by:erde
ID: 7138004
Works fine. Thanks.
0
 
LVL 4

Expert Comment

by:brokeMyLegBiking
ID: 11379519
solved my problem as well!

-grateful bystander
0
 
LVL 4

Expert Comment

by:Danielcmorris
ID: 14894313
very slick!  thanks dewpat
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now