I'm doing a fairly straight forward import of a .csv file that is provided by a vendor using the following command (I have abbreviated it a bit):
Insert Into ... From OPENROWSET (Bulk 'CSVFileName', FORMATFILE ='XMLFormatFileName', FIRSTROW = 2, MAXERRORS = 0 ) AS BulkLoadFile
The CSV file format looks like the following (you may need to click to see the image since I'm new to StackOverflow I cannot directly post images yet):
https://i.stack.imgur.com/qZMwV.jpg
My problem is the LAST ROW with the count... It causes the import to fail!
FYI >>> Yes I know you can use "SET NOCOUNT ON;" but I do not generate this file, so that is not an option.
Right now I open the file and delete the last row and then re-save before importing. (note: I also delete the top 2 rows shown in green since I'm already in the file, but the two first rows are not an issue as I can skip those rows using FIRSTROW = 4 switch).
So my questions are:
Is there any way to SKIP LAST ROW?
OR
Is there any way to get a row count and maybe use the LAST ROW switch? i.e. LAST ROW = Count(*) from myCSVfile
OR
Since it always starts like "Total:" is there anyway to add a WHERE clause? i.e. WHERE value in first column is not like 'Total:%'
OR
Is this something that SSIS would handle better? If so I can move this import routine over to SSIS.
Thanks in advance... I look forward to truly automating this and not having to open this file every time we import it (multiple times a day).
D3Y