Reputation: 53
I am doing a batch process. In my process I build a set of insert query statements and will run from my application. I won't use sql transactions and want to skip the statement which throws error.
For example:
create table test
(
test varchar(20)
)
insert into test (test) values ('test1'); -- 1 row affected
insert into test (test) values ('test2'); -- 1 row affected
insert into test (test) values ('a' + 333); -- This will throw error while executing and i ---want to skip this
insert into test (test) values ('test4'); -- This should be affected as per my requirement
Is it possible such type of process?
Upvotes: 1
Views: 6570
Reputation: 1450
Wrapping each insert statement in try catch block can solve the problem.
Upvotes: 0
Reputation: 432451
Like this you can't, unless you do one of
bcp and BULK INSERT have a MAXERRORS option which isn't exposed in the .net SQLBulkCopy class, which may be better way to do it...
Upvotes: 2
Reputation: 5029
You could just surround each INSERT statement with a try-catch block, e.g.
BEGIN TRY
INSERT INTO test...
END TRY
BEGIN CATCH
--Do nothing
END CATCH
Upvotes: 2