Exception Handling in Dynamic SQL in SQL Server -
in dynamic sql statement 1 @stu_id value failing insert data table. here need know @stu_id if failing when execution.
create proc data_copy ( @src_table varchar(30), @dest_table varchar(30) ) declare @stu_id int begin declare student_cursor cursor select distinct stu_id student open student_cursor fetch next student_cursor @stu_id while @@fetch_status = 0 begin exec ('insert '+@dest_table+' select * '+@src_table+' stu_id='+@stu_id) fetch next student_cursor @stu_id end close student_cursor deallocate student_cursor end
can me how ?
thanks
you can capture data during context of error try catch
begin try exec ('insert '+@dest_table+' select * '+@src_table+' stu_id='+@stu_id) end try begin catch print 'error value @stu_id = ' + convert(varchar,@stu_id) end catch
Comments
Post a Comment