Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Importing COBOL generated Text file
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/18/2013 :  16:39:05  Show Profile  Reply with Quote
I am generating a text file in a COBOL program to BULK insert into a temp table. I am getting data conversion errors I believe because it thinks there are no end of line characters at the end of each row. What is the hex value for an end of line character? I am using a tab for a field delimiter.


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 11/18/2013 :  17:52:03  Show Profile  Reply with Quote
Depending on where you generated the file, it might be a carriage return, a linefeed or a CR+LF. You can use a text editor such as TextPad that can show binary characters to open the file and see what the end of line character(s) is. Once you find that, do something like shown below. Here I am using tab as the field separator and LF as the row separator. (I am going to the extreme here using dynamic SQL, you probably wouldn't need to do that, but this should work. Just be careful about sql injection if you end up using dynamic sql.

DECLARE @filename NVARCHAR(128) = '\\yourdomain\yourshare\yourfolder\yourcolbofile.txt';
DECLARE @sql NVARCHAR(4000) = '
	FROM '''
		+ @filename + 
	''' WITH 
		FIELDTERMINATOR = ' + CHAR(9) + -- tab
		', ROWTERMINATOR = ''' + CHAR(10) + ''' 

EXEC (@sql);
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000