473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sql server transaction syntax help

Hi,

I have an issue with my query.

1. I have 1 stored proc which have execution calls to multiple stored
procs within it.

2. I want to wrap that main stored proc in the transaction and rollback
if there are errors execution calls to other stored procs. I don't
believe my code is accounting for errors occuring in the execution
statement to other stored proc.

3. Is there an easy way to do this without creating tranaction on each
stored proc and returning the error code? How do I make this happen?
Below is the code.

Thanks

:D
ALTER procedure spAG_Add_Product
@prodCost money,
@prodWeight decimal,
@prodDesc nvarchar(100),
@prodName nvarchar(50),
@prodSize nvarchar(100),
@pic_filename nvarchar(50),
@userId int,
@exhib_id int
AS

declare @auth_Logic_id int
declare @intErrorCode int
BEGIN TRAN

SELECT @auth_Logic_id= AG_Auth_Logic.Auth_Logic_ID FROM
AG_Auth_Logic
INNER JOIN AG_Base_Active_State ON AG_Auth_Logic.Base_Active_State_ID
= AG_Base_Active_State.Base_Active_State_ID
WHERE AG_Auth_Logic.Action_Description LIKE N'%category%'
AND AG_Base_Active_State.Is_Alive = 1

INSERT INTO AG_Individual_Product
(
Product_cost,
Product_weight,
Product_description,
Product_name,
User_ID,
Auth_Logic_Id,
Product_size
)
VALUES (
@prodCost,
@prodWeight,
@prodDesc,
@prodName,
@userId,
@auth_Logic_id,
@prodSize
)

declare @prod_id int
select @prod_id = Scope_identity()

-- add to pic table
declare @pic_id_out int
exec spAG_Add_Picture @pic_filename,
@prodName, @pic_id = @pic_id_out output

declare @prod_pic_out int
-- add to product_pic table
exec spAG_Add_Product_Picture @pic_id_out,
@prod_id, @prod_pic_id = @prod_pic_out output

-- add to product_pic_in_exhib
exec spAG_Add_Product_Picture_in_Exhibition @prod_pic_out,
@exhib_id, @prod_id

select @prod_id

SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRAN

PROBLEM:
IF (@intErrorCode <> 0) BEGIN
ROLLBACK TRAN
END

Jul 23 '05 #1
1 3914

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anjula | last post by:
I have a stored procedure that takes 18 hours to complete. Sometimes I get the below error message when I run the stored procedure. 'Server : Msg 9002, Level 17, State 6, Line 1 The log file for...
12
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the...
0
by: Raja | last post by:
I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle Database. The Link is perfect and dont have any problems in accessing the data from SQL Server 2000. The only problem i am...
1
by: dschneiderman | last post by:
Hello All, I am not a SQL Server expert, but I have been put in a pretty precarious situtation and I am close to panicking :( I have need to restore a SQL database from backup (through...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
3
by: RayPower | last post by:
I'm having a system using Access 2000 as both front-end (queries, forms, reports & temp tables for reports) & back-end (data) with back-end running on the server. The application runs on the...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
19
by: dunleav1 | last post by:
I built a test job that loads data into the database. I get great performance with Oracle and I'm trying to tune Sql Server to get the same type of performance. Based on system monitoring it...
1
by: toori | last post by:
i am new to the JAVA...Any one help to make codes for this server client application program "Design and implement a server application which acts as an Internet bank, i.e. keeps track of bank...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.