Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-03 : 09:59:20
|
| Andy writes "Is there anyway to trap for a data conversion error in code. Example:Table 1line_1 int,line_2 varchar(40),line_3 varchar(40),line_4 varchar(40)Then have a sproc as follows that tries to insert a varchar into an int datatype:CREATE PROCEDURE [DBO].[TEST1] ASBEGIN declare @iError intINSERT Table1(LINE_1, LINE_2, LINE_3, LINE_4) VALUES ('tw','test', 'test', 'Y') Select @iError=@@errorIf @iError <> 0 Print 'Error' END GOWhen the sproc is run using Exec TEST1 I get this:Server: Msg 245, Level 16, State 1, Procedure TEST1, Line 17Syntax error converting the varchar value 'tw' to a column of data type int.I am trying to get the error code returned." |
|
|
dsdeming
479 Posts |
Posted - 2002-04-03 : 13:07:15
|
| I don't know of any way to do what you're asking short of running ISNUMERIC, ISDATE, etc on the data before attemping the insert or update. |
 |
|
|
Onamuji
Aged Yak Warrior
504 Posts |
Posted - 2002-04-03 : 13:25:30
|
| Look SET ARITHIGNORE up in BOL. |
 |
|
|
|
|
|
|
|