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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 procedure error

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2006-12-15 : 07:31:03
below code is working fine,while passing query correctly
if i pass the value like this:
exec proctest('rab44','sent','25','fff')
this gets rollbacked correctly..Just i need to know where the error occured whether in first begin,end statment or the second one and then the type of error occured

create procedure proctest(@idno char(7),@name varchar(9),@age int,@wages decimal(15,2))
as
declare @err int
set nocount on

begin transaction
begin
insert into gworker(idno,name) values(@idno,@name)
set @err=@@error
if @err<>0
rollback tran
end

begin
insert into oworker(idno,age) values(@idno,@age)
@err=@@error
if @err<>0
rollback tran
end

begin
insert into msalary(idno,wages) values(@idno,@wages)
@err=@@error
if @err<>0
rollback tran
end
commit transaction
end transaction

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2006-12-15 : 07:51:13
create procedure ...
as
@err int

should be

create procedure ...
as
DECLARE @err int


--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-12-18 : 00:21:33
quote:
Originally posted by sent_sara

below code is working fine,while passing query correctly
if i pass the value like this:
exec proctest('rab44','sent','25','fff')
this gets rollbacked correctly..Just i need to know where the error occured whether in first begin,end statment or the second one and then the type of error occured

create procedure proctest(@idno char(7),@name varchar(9),@age int,@wages decimal(15,2))
as
declare @err int
set nocount on

begin transaction
begin
insert into gworker(idno,name) values(@idno,@name)
set @err=@@error
if @err<>0
rollback tran
end

begin
insert into oworker(idno,age) values(@idno,@age)
@err=@@error
if @err<>0
rollback tran
end

begin
insert into msalary(idno,wages) values(@idno,@wages)
@err=@@error
if @err<>0
rollback tran
end
commit transaction
end transaction




Just check, you were passing non numeric values to 3rd and 4th params, as they must be numeric. let us know, if u have any problem.

Mahesh
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-18 : 10:16:31
www.sommarskog.se/error-handling-I.html
www.sommarskog.se/error-handling-II.html


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -