Solved

Bulk insert

Posted on 2002-07-02
5
1,504 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
[X]
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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database 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.

691 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