Hi,
I'm using BULK INSERT to import data from multiple sequentially numbered text files into my database.
My code works fine and all is well until a particular file doesn't exist.
What i want is to skip the BULK INSERT process and increment the @Practice variable by 1 in the event that a particular file is missing. At present i have no '116' file, so the SP stops when the error occurs.
I've looked at BREAK and RETURN but i'm not sure they're what i'm after, in VB i'd use 'ON ERROR GOTO', is there a similar function in T-SQL?
Does anyone have any suggestions?
Cheers,
Leigh
Sure, if it has a microchip in it, it must be IT... Now what seems to be the problem with your toaster...?
I'm using BULK INSERT to import data from multiple sequentially numbered text files into my database.
My code works fine and all is well until a particular file doesn't exist.
Code:
DECLARE @Practice int
DECLARE @File varchar(255)
DECLARE @SQL varchar(8000)
SET @Practice = 101
WHILE @Practice <= (SELECT MAX(PracticeID)
FROM Vets4Pets_Info..[List - Practices])
BEGIN
SET @File = 'E:\RxWorks\DataExtracts\' + CONVERT(char(3), @Practice) + '_C_Data.txt'
PRINT @File
SET @SQL = N'BULK INSERT Marketing..Client_Raw
FROM ''' + @File + '''
WITH
(
FIELDTERMINATOR = ' + ''',''' + ',
ROWTERMINATOR = ' + '''\n''' + ',
FIRSTROW = 2,
KEEPNULLS
)'
PRINT @SQL
EXEC (@SQL)
SET @Practice = @Practice + 1
END
What i want is to skip the BULK INSERT process and increment the @Practice variable by 1 in the event that a particular file is missing. At present i have no '116' file, so the SP stops when the error occurs.
I've looked at BREAK and RETURN but i'm not sure they're what i'm after, in VB i'd use 'ON ERROR GOTO', is there a similar function in T-SQL?
Does anyone have any suggestions?
Cheers,
Leigh
Sure, if it has a microchip in it, it must be IT... Now what seems to be the problem with your toaster...?