Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !

I want check error in Stored Procedure.How it can be created ? Please give very simple example.
Posted

create Procedure [dbo].[spGetPrint]

(
@PrintDate DateTime,
@StartUpFlag Bit
)
As

Begin Transaction
Update PrintList Set IsPrinted = 0 Where 1 = 0
Select
PrintID, PrintTypeID, PrintDate, MakerID, MakerTime, TerminalID,
AccMasterID, AccDetailsID, TransID, IsDuplicate
From PrintList Where IsPrinted = 0 And (IsSelected = 0 Or @StartUpFlag = 1)
Update PrintList Set IsSelected = 1 Where IsPrinted = 0 And IsSelected = 0
Commit Transaction
 
Share this answer
 
Comments
LebneizTech 28-Apr-11 7:24am    
Hi ! It is correct.But you donot use @@error.

On Error: whether is RollBack or not without using @@error ?
Try this one,

Begin Try
Begin Transaction
"Wrie ur sql query here"
Commit Transaction
End Try
Begin Catch
If @@TRANCOUNT > 0
Rollback Transaction
End Catch
 
Share this answer
 
SQL
USE TempDB;
GO

CREATE TABLE ValueTable ([value] int)
GO

DECLARE @TransactionName varchar(20) = 'Transaction1';

--These statements start a named transaction,
--insert a two records, and then roll back
--the transaction named in the variable
--@TransactionName.
BEGIN TRAN @TransactionName
       INSERT INTO ValueTable VALUES(1)
       INSERT INTO ValueTable VALUES(2)
ROLLBACK TRAN @TransactionName

INSERT INTO ValueTable VALUES(3)
INSERT INTO ValueTable VALUES(4)

SELECT * FROM ValueTable

DROP TABLE ValueTable
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900