Why @@Error Is not Working
-
I have simple situation...Here explicitly i am trying to insert char instead of integer and want to throw exception. But instead of printing "a" i am getting "Conversion failed when converting the varchar value 'a' to data type int." .... ANY REASONS WHY??? CREATE TABLE Temp(C Int) GO INSERT INTO Temp VALUES('a') IF @@ERROR <> 0 BEGIN print 'a' END Amit
-
I have simple situation...Here explicitly i am trying to insert char instead of integer and want to throw exception. But instead of printing "a" i am getting "Conversion failed when converting the varchar value 'a' to data type int." .... ANY REASONS WHY??? CREATE TABLE Temp(C Int) GO INSERT INTO Temp VALUES('a') IF @@ERROR <> 0 BEGIN print 'a' END Amit
Use this way to to do so: Declare @vError varchar(4000) Select @vError = convert( varchar,@@Error) IF @vError <> '0' GOTO ErrorHandler ErrorHandler: IF @vError = '0' BEGIN Commit Tran Return 0 -- On Success END Else BEGIN Rollback Tran Return @vError -- On failure END
fasih_is_my_signature