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

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Importing COBOL generated Text file

Author  Topic 

VickiPugliese
Starting Member

1 Post

Posted - 2013-11-18 : 16:39:05
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-18 : 17:52:03
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
   

- Advertisement -