Advertisement

01.30.2008 at 05:13AM PST, ID: 23122568
[x]
Attachment Details

just a double check on my transaction logic

Asked by dbaSQL in MS SQL Server

I just was hoping somebody could double-check my tran logic herein --- basically, i have two identical tables --- @flag defaults to 0, but if @flag = F, i should insert into QHFinal table..  else, i should insert into QH table.  
i often times get a little screwed up on the flow control, and the error handling.  
(begin tran/begin/end/end/end/commit tran)  

is this correct?

CREATE PROC procedurename (
 @field1...
 @field2...
 ...
 @flag char(1)=0
)
AS
SET NOCOUNT ON
BEGIN
/*  created for the insertion into QH/QHFinal tables  */

BEGIN TRANSACTION
IF(@flag='F')
  BEGIN
      INSERT INTO database.dbo.QHFinal (
      [........bunch of fields.......]  )
      VALUES (@.........same bunch of fields..... )
      SELECT SCOPE_IDENTITY() AS QHID
      
      IF @@ERROR <> 0
      BEGIN
          RAISERROR('Failed to insert into database.dbo.QHFinal',16,-1)
          RETURN
      END
  END
  ELSE
  BEGIN
      INSERT INTO database.dbo.QH (
      [......bunch of fields....... )
      VALUES (@..........same bunch of fields........ )
      SELECT SCOPE_IDENTITY() AS QHID

      IF @@ERROR <> 0
      BEGIN
          RAISERROR('Failed to insert into database.dbo.QH',16,-1)
          RETURN
      END

      IF @@ERROR = 0
      BEGIN
            COMMIT TRANSACTION
      END
  END
ENDStart Free Trial
 
Loading Advertisement...
 
[+][-]01.30.2008 at 05:15AM PST, ID: 20776680

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:17AM PST, ID: 20776695

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:33AM PST, ID: 20776811

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:34AM PST, ID: 20776822

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: lexiflex
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.30.2008 at 05:35AM PST, ID: 20776833

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:42AM PST, ID: 20776879

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:46AM PST, ID: 20776899

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:47AM PST, ID: 20776915

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:53AM PST, ID: 20776955

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 05:58AM PST, ID: 20776990

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2008 at 06:07AM PST, ID: 20777046

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.01.2008 at 08:24AM PST, ID: 20797913

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628