I have a transaction that is doing an insert. when I do the insert alone i get the following error:
Msg 8152, Level 16, State 13, Line 1
String or binary data would be truncated.
The statement has been terminated.
The error is correct, one of the columns contains more data that the column size of the destination. However, the begin catch does not catch this error. The data gets truncated and the data is still inserted. I do not get a print out of the error. How can I modify the transaction so it will catch this error?
insert into table1 (col1, col2)
select col1, col2 from table2
IF @@TRANCOUNT > 0
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)