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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error Handling

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-07-14 : 02:52:32
Iam not able to get the error number.
can any one correct???.
Note:Hello_test table 1 value is of integer second is of character

Declare @error int
declare @test_error int
set @error=0
exec @test_error=Hello_test1_sp @error output
print @test_error

alter procedure Hello_test1_sp(@err int output)
as
begin
set nocount on
Declare @er int



begin tran
insert into hello_test values('f','M')
if @@error<>0
begin
set @er=@@error
return @er
rollback tran
end
else
begin
commit tran
end


set nocount off

end

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-07-14 : 04:14:20
[code]if @@error<>0
begin
set @er=@@error
[/code]
The if statement sets @@error back to 0. @@error contains the error code of the last statement, so everything resets it.

You'll have to do something like this rather.
[code]set @er=@@error
if @er<>0
begin[/code]
-
Gail Shaw
SQL Server MVP
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-07-14 : 06:34:52
txs mr.GilaMonster.i understood

quote:
Originally posted by GilaMonster

if @@error<>0 
begin
set @er=@@error

The if statement sets @@error back to 0. @@error contains the error code of the last statement, so everything resets it.

You'll have to do something like this rather.
set @er=@@error
if @er<>0
begin

-
Gail Shaw
SQL Server MVP

Go to Top of Page
   

- Advertisement -