bebblebrox
IS-IT--Management
I have a script which uses a cursor (cursor use is not the topic though ). There are some records that, for various reasons, cause an errors such as:
1. can't insert null
2. data would have been truncated
3. eetc
which cause the statement to be aborted. My question is: what construct do i need to use in order for the procedure to continue.
my script looks something like:
when the above inserts cause errors, i want to take some action and then move on to the next record in the cursor.
what am i doing wrong?
thanks!
1. can't insert null
2. data would have been truncated
3. eetc
which cause the statement to be aborted. My question is: what construct do i need to use in order for the procedure to continue.
my script looks something like:
Code:
Declare vars
--create cursor of existing records
DECLARE cMembers CURSOR for blah
begin
open cMembers
fetch next from cMembers
while @@FETCH_STATUS = 0 Begin
fetch next from cMembers into @vars
--clean up data
--insert record
insert into table (sometimes this causes errors)
(
columns
)
values
(
@vars
)
set @ErrorNo = @@Error
if @ErrorNO <> 0
Begin
--do something
End
Begin
INSERT INTO table (sometimes this causes errors)
SELECT columns
FROM table
where conditions
set @ErrorNo = @@Error
if @ErrorNO <> 0
Begin
--do something
End
end
end
close cMembers
deallocate cMembers
end
when the above inserts cause errors, i want to take some action and then move on to the next record in the cursor.
what am i doing wrong?
thanks!