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.
Author |
Topic |
celv
Starting Member
6 Posts |
Posted - 2015-05-07 : 03:38:24
|
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[sectionexpenses] (@sectionname varchar(30),@ExpensesName varchar(max),@Date varchar(30),@BillNo varchar(max),@BillAmount float,@currentdate varchar(50),@partydetz varchar(max),@bdate datetime)ASDECLARE @Result intBEGIN TRANSACTION IF EXISTS( SELECT * FROM expenzsection WHERE sectionname=@sectionname and partydetz=@partydetz and BillNo=@BillNo and BillAmount=@BillAmount )BEGIN SELECT @Result = -1 ENDELSEbegininsert into Expenzsection(sectionname,ExpensesName,Date,BillNo,BillAmount,currentdate,partydetz,bdate)values(@sectionname,@ExpensesName,@Date,@BillNo,@BillAmount,@currentdate,@partydetz,@bdate) SELECT @Result = @@ERRORendIF @Result <> 0 BEGIN ROLLBACK ENDELSE BEGIN COMMIT ENDRETURN @Resultcelv |
|
Kristen
Test
22859 Posts |
Posted - 2015-05-07 : 05:20:51
|
What happens if another user adds a duplicate row to expenzsection between your IF EXISTS and yourinsert into Expenzsection ??I know that situation would be very rare but if it happens it will be completely unreproducible and very hard to debug.You could look at isolation levels, orINSERT INTO Expenzsection(...SELECT @sectionname,...WHERE NOT EXISTS( SELECT * FROM expenzsection WHERE ...)SELECT @Result = CASE WHEN @@ROWCOUNT = 0 THEN -1 ELSE @@ERROR END |
|
|
celv
Starting Member
6 Posts |
Posted - 2015-05-07 : 08:08:21
|
sir please put the sample code i can't understand itcelv |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-05-07 : 09:10:40
|
quote: Originally posted by celv sir please put the sample code i can't understand itcelv
Kristen posted sample code for youGerald Britton, MCSAToronto PASS Chapter |
|
|
|
|
|
|
|