Solved

Bulk insert

Posted on 2002-07-02
5
1,482 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Oracle SQL with Connect by prior to SQL Server SQL 6 30
SQL Query 17 30
Alter table 4 22
SQL Query resolving a string conversion issue 26 37
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

932 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

15 Experts available now in Live!

Get 1:1 Help Now