bulkinsert - SQL Server 2012 - Bulk Insert FIRSTROW = 2 skips the 2nd row -
i need skip first , last rows in text file. this, first bulk insert file without parsing fields , count how many rows has in staging table. use dynamic sql code insert file table:
select @last_row = max(id) pre_staging_table select @last_row = cast(@last_row bigint) - 1 select @bulk_insert = ' bulk insert staging_table ''' + @filename + ''' ( firstrow = 2 , lastrow = ' + @last_row + ' , fieldterminator = ''' + @field_terminator + ''' , rowterminator = ''' + char(10) + ''' ) ' exec(@bulk_insert)
the problem... starts final bulk insert using 3rd row of file! why in world happening? when bulk insert pre-staging table, rows inserted. not firstrow or lastrow filter there.
here first 4 rows of data file:
09.0|a|data|start|20140626|20140626|005221|a| 346| |001|33 |p|flip |2014|00000|00|l|o|0| |0000000015|0| | |snap |19|000350000|00100| | | | | | | | | |4|000| | |aa |2014|01|01| |# 346| |001|33 | |flip |2014|00000|00|l|o|0| |0000000150|0| | |snap |00|000000000|00100| | | | | | | | | |4|000| | |aa |2014|01|01| |# 346| |001|33 |p|flip |2014|00000|00|l|o|0| |0000000027|0| | |snap |22|000125000|00100| | | | | | | | | |4|000| | |aa |2014|01|01| |#
the lines end lf, not crlf. i'm wondering if code having problems that. read other thread , did not solve problem since looks header row contain @ least 1 delimiter found in other rows.
update: have gotten around exporting data in pre-staging table new text file rows want , re-importing them.
Comments
Post a Comment