Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Bulk Insert for text file with irregular terminators

$
0
0
I have run into an issue with several clients when importing their files into tables. I can manually import by using the Import\Export wizard and hit the correct row count. However, using OpenRowSet and Bulk insert, I come up rows short. Searching down into the millions of lines, I find areas where the field terminator suddenly changes from the default "tab" to just a singular space and then back again. This results in a shorter row count as the bulk insert fills the fields with the next available data. Does anyone know of a way to handle this? I realize that we can build an SSIS package, but the insert needs to be called from a routine. The clients are reluctant to change their exports and are working through Zerion. The code below is what I am executing through a called stored procedure passing @pathTruncate table tblClientDataDECLARE @SQL_BULK VARCHAR(MAX)Set @SQL_BULKInsert = 'BULKINSERT tblClientDataFROM '''+ @path +''' WITH(FIELDTERMINATOR = ''\t'',OWTERMINATOR = '''',FIRSTROW=2 )'Exec(@SQL_BULKInsert)Thank you in advance for your ideas and suggestionsjfh2841

Viewing all articles
Browse latest Browse all 3145

Trending Articles