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)
 Why I need to commit.

Author  Topic 

dtong004
Constraint Violating Yak Guru

281 Posts

Posted - 2001-08-08 : 18:35:02
I have a stored prcedure to insert data into a table.
I call exec sp_, It increase my @@trancount.

I have to give "commit" to commit the insert process.

Does anyone know what happend:

Here is the code:

CREATE PROCEDURE CASH_BUILD_P
AS

SET ANSI_DEFAULTS ON
SET NOCOUNT OFF

DECLARE @RUNLOG INT
SELECT @RUNLOG=CONVERT(INT, CONVERT(VARCHAR(8), GETDATE(),12))

BEGIN TRAN
INSERT MGMT..CASH_NEW (RUNLOG_ID, XYZ, CSTATE, CZIP, EMP_ID)
SELECT @RUNLOG, XYZ, CSTATE, CZIP, U.I_ID
FROM CASH_BCP C LEFT OUTER JOIN CASH..UNITS U
ON C.UNIT=U.UNIT

IF @@ERROR<>0
BEGIN
RAISERROR ( 'LOADING CASH ERROR HAPPENED', 16, 1)
ROLLBACK TRAN
END

ELSE
BEGIN
PRINT ' LOADING CASH SUCCESSFUL. ************************************************'
COMMIT TRAN
END
RETURN
GO



   

- Advertisement -