SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

VickiPugliese
Starting Member

USA
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.

Thanx.
Vicki

James K
Flowing Fount of Yak Knowledge

3742 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) = '
	BULK INSERT 
		YourTableName
	FROM '''
		+ @filename + 
	''' WITH 
	(
		FIELDTERMINATOR = ' + CHAR(9) + -- tab
		', ROWTERMINATOR = ''' + CHAR(10) + ''' 
	);';

EXEC (@sql);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000