473,587 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BULK INSERT row terminator issue

9 New Member
Hi everyone,

I receive a variety of text based files that seperates each row by a single delimiter, usually '~'. I use BULK INSERT to transfer the file from a text file to a temporary table. It works fine for most of the files (which use '~' as the delimiter for the rows), but for some reason I can't get it to work for a particular file.

The file looks like it uses a new line character as the row delimiter, so I put in '\n' as the row delimiter but it didn't work. I also tried '\r' and '\r\n' and '\n\r' and none of them work. I then ran a script to return every ASCII value in the file and for each break that starts a new row, it gave 2 ASCII values: 11 (tab) and 13 (carriage return) so I tried '\t\r' and '\t\n' and that didn't work. Any ideas on how to get it to split it up into rows? I can't think of any other solution except changing the file before but it seems like it should work somehow through BULK INSERT.

I don't know if it helps or not but below is part of the sproc I'm using (like I said before, it works fine with all other files):

Expand|Select|Wrap|Line Numbers
  2.     -- Generate query
  3.     SET @Query = 'BULK INSERT #FileBase FROM "' + @FILE_PATH + '"'    
  4.     SET @Query = @Query + ' WITH ('
  5.     SET @Query = @Query + 'CODEPAGE = ''RAW'', ROWTERMINATOR = ''' + @ROW_TERM + ''''
  6.     SET @Query = @Query + ')'
  8.     EXEC(@Query)
Thank you,

Feb 9 '09 #1
2 5883
30 New Member
We ended up figuring out a fix. We just added:

Expand|Select|Wrap|Line Numbers
  1. IF @ROW_TERM = '\n' SET @ROW_TERM = CHAR(10)
I'm not exactly sure why \n doesn't work by itself in this instance but that fix seemed to work.
Feb 11 '09 #2
1 New Member
this works out in my case too... strange~
Feb 12 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Jim Geissman | last post by:
I am trying to bulk insert a text file. The file has fixed-length fields with no field terminators. BOL says that field terminators are only needed when the data does *not* contain fixed-length fields, which implies they are optional -- so I made a format file without any (two consecutive tabs with nothing between them). The following...
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. When I execute the query, I get an error saying that only sysadmin or bulkadmin roles are allowed to use the BULK INSERT statement. So, I...
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or big) problem with my code that someone can point out that may save me some time. TIA CBL
by: joshsackett | last post by:
Hello all, I have a multiple text files with an odd row terminator. If you were to examine it in VB it would be like a "CrCrLf" instead of just "CrLf". In HEX it is DDA instead of just DA. When I am trying to import into my table using BULK INSERT I use "\n" as the row terminator but that is putting the the previous character into the column...
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of 10 columns into a table with 12. How can I specify which columns to insert to? I think format files are what I'm supposed to use, but I can't...
by: Mike Husler | last post by:
We have created CSV files on HPUX 11.0 and transferred them via ASCII ftp to our SQL Server machine file store to load large amounts for data using the BULK INSERT command. This is the command: BULK INSERT db..table FROM 'S:\path\filename.csv' WITH ( DATAFILETYPE = 'char', FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
by: Ted | last post by:
I used bcp to produce the apended format file. How can it be modified to recognize the quotes that surround the text fields and not insert the quotes along with the text? Invariably, the first four columns have text surrounded by quotes and are terminated by tabs. If the first column has "abc", only abc ought to be inserted into that...
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of format file" Question:
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.