I just want to ask if there is a way to use the bulk insert feature but to check if the last line is empty and skip it.
I have a text file that is being populated with data but the last line will always be empty cause when it repopulates, it will start from there and the the end of the previous line that is already populated.
My query so far looks like this:
BULK INSERT #TEMP FROM 'C:\Test\Test.txt' WITH (FIELDTERMINATOR ='\t', ROWTERMINATOR = '\r', FIRSTROW = 2, KEEPNULLS)It will then be input into a temp table but the query will not go this far because of the last line in the text file. Is there a setting to say, skip the last line if its empty?
If you're expecting one line to be nonimportable then include
MAXERRORS =1In the command and BULK INSERT should import the other ones fine.
BULK INSERT #TEMP FROM 'C:\Test\Test.txt' WITH (FIELDTERMINATOR ='\t', ROWTERMINATOR = '\r', MAXERRORS =1, FIRSTROW = 2, KEEPNULLS)Unless there's an unexpected problem in another line (in which case you'll want to trap the error anyway)
https://msdn.microsoft.com/en-us/library/ms188365.aspx