Note that there are some explanatory texts on larger screens.

plurals
  1. POException handling in SQL Server 2000
    primarykey
    data
    text
    <p>I have a procedure that gets data from a table and inserts it into a temporary table. Then the procedure validates one by one in a while loop.</p> <p>For example: I have 50 rows and the first row fails. In that case, I wish that the procedure continues processing the remaining 49 rows.</p> <p>I'm forcing an error in an insert statement and and I put under it <code>@@error &lt;&gt; 0</code> but does not enter if block.</p> <p>But procedure ends and doesn't continues with the next statement to be executed.</p> <p>I am running the procedure from Query Analyzer and put message with print 'line 1' etc etc.</p> <p>Thank you for your help.</p> <p>This is a similar example</p> <pre><code>create procedure procx as declare @ind_max int, @ind int, @var_id int, @var_name varchar(3) declare @table_x table ( row_id int identity(1,1), id_x int, name_x varchar(25), status_x int ) insert into @table_x values(1, 'xxx', 0) insert into @table_x values(2, 'yyy', 0) insert into @table_x values(3, 'zzz', 0) set @ind_max = 3 set @ind = 1 while (@ind &lt;= @ind_max) begin print 'line 1' select @var_id = id_x , @var_name = name_x from @table_x where row_id = @ind -- Forced error id_x is int field -- Doesn't show line2, line3 ... -- Msg 245, Level 16, State 1, Procedure procx, Line 160 -- Syntax error converting the varchar value 'A' to a column of data type int. insert into test ( id_x , name_x ) values ( 'A' , @var_name ) if @@error != 0 begin print 'line 2' goto next_row insert into log_test values(@var_id, 'Error') end print 'line 3' update @table_x set status_x = 1 where row_id = @ind print 'line 4' next_row: set @ind = @ind + 1 end print 'line 5' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload