Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Bulk insert

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

828 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