Click here to Skip to main content
15,894,017 members
Home / Discussions / Database
   

Database

 
AnswerRe: Check for Null or Empty In SP Pin
Wendelius4-Sep-11 21:40
mentorWendelius4-Sep-11 21:40 
GeneralRe: Check for Null or Empty In SP Pin
Rakesh Meel6-Sep-11 2:50
professionalRakesh Meel6-Sep-11 2:50 
AnswerRe: Check for Null or Empty In SP Pin
PIEBALDconsult5-Sep-11 4:35
mvePIEBALDconsult5-Sep-11 4:35 
AnswerRe: Check for Null or Empty In SP Pin
Ganu Sharma15-Sep-11 20:38
Ganu Sharma15-Sep-11 20:38 
AnswerRe: Check for Null or Empty In SP Pin
Ganu Sharma5-Oct-11 2:15
Ganu Sharma5-Oct-11 2:15 
QuestionPatch for bug with SqlBulkCopy - installation problem Pin
devvvy2-Sep-11 20:39
devvvy2-Sep-11 20:39 
AnswerRe: Patch for bug with SqlBulkCopy - installation problem Pin
Wendelius3-Sep-11 4:29
mentorWendelius3-Sep-11 4:29 
Questionmismatching number of BEGIN and COMMIT statements (T_SQL) [modified] Pin
Naunt1-Sep-11 18:07
Naunt1-Sep-11 18:07 
Dear all,

Please kindly advise this, my storeprocedure structure is as below.
The purpose is, While Insert in TableA if there is any error occour Then I want to ROLLBACK TRAN of TableB that related with the current Transaction of TableA, if not COMMIT TRAN.

When execute it I have got the error
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1159.


SQL
DECLARE Cur_1 Cursor LOCAL FOR
  Select col1,col2,col3 from table1
OPEN Cur_1
FETCH NEXT FROM  Cur_1
	INTO @col1,@col2,@col3

	WHILE @@FETCH_STATUS = 0 
	BEGIN
			
	    DELETE FROM FROM TableA Where match with @col1,@col2,@col3
	    DELETE FROM FROM TableB Where match with @col1,@col2,@col3

            DECLARE Cur_2 LOCAL FOR		
	     Select * from table2 Where match with @col1,@col2,@col3
		 OPEN Cur_2
		 FETCH NEXT FROM  Cur_2

   		 WHILE @@FETCH_STATUS = 0 
		 BEGIN
BEGIN TRAN						
			INSERT INTO TableB (data from Cur_2 & Cur_1)
						
		    FETCH NEXT FROM  Cur_2
		 END
		 CLOSE Cur_2
		 DEALLOCATE Cur_2					
			
	    INSERT INTO TableA (data fromCur_1)
			
	    IF @@ERROR = 0
		COMMIT TRAN
	    ELSE
		ROLLBACK TRAN

 	    FETCH NEXT FROM  Cur_1
		INTO @col1,@col2,@col3
	END

	CLOSE	Cur_1
	DEALLOCATE Cur_1


modified on Friday, September 2, 2011 12:35 AM

AnswerRe: mismatching number of BEGIN and COMMIT statements (T_SQL) Pin
Geoff Williams1-Sep-11 23:42
Geoff Williams1-Sep-11 23:42 
AnswerRe: mismatching number of BEGIN and COMMIT statements (T_SQL) Pin
Shameel2-Sep-11 4:02
professionalShameel2-Sep-11 4:02 
AnswerRe: mismatching number of BEGIN and COMMIT statements (T_SQL) Pin
Ganu Sharma15-Sep-11 20:59
Ganu Sharma15-Sep-11 20:59 
Questionis it true about MSSQL Database server Pin
netJP12L1-Sep-11 5:05
netJP12L1-Sep-11 5:05 
AnswerRe: is it true about MSSQL Database server Pin
Corporal Agarn1-Sep-11 7:01
professionalCorporal Agarn1-Sep-11 7:01 
AnswerRe: is it true about MSSQL Database server Pin
Mycroft Holmes1-Sep-11 13:00
professionalMycroft Holmes1-Sep-11 13:00 
GeneralRe: is it true about MSSQL Database server Pin
Corporal Agarn2-Sep-11 3:01
professionalCorporal Agarn2-Sep-11 3:01 
GeneralRe: is it true about MSSQL Database server Pin
crocks2565-Sep-11 2:39
crocks2565-Sep-11 2:39 
GeneralRe: is it true about MSSQL Database server Pin
Chris Meech2-Sep-11 3:15
Chris Meech2-Sep-11 3:15 
GeneralRe: is it true about MSSQL Database server Pin
Wendelius3-Sep-11 6:52
mentorWendelius3-Sep-11 6:52 
GeneralRe: is it true about MSSQL Database server Pin
S Douglas13-Sep-11 18:21
professionalS Douglas13-Sep-11 18:21 
QuestionMs Access file Missing Pin
sudheesh kumar s31-Aug-11 20:45
sudheesh kumar s31-Aug-11 20:45 
AnswerRe: Ms Access file Missing Pin
Blue_Boy31-Aug-11 21:12
Blue_Boy31-Aug-11 21:12 
AnswerRe: Ms Access file Missing Pin
Mycroft Holmes31-Aug-11 22:55
professionalMycroft Holmes31-Aug-11 22:55 
AnswerRe: Ms Access file Missing Pin
jschell1-Sep-11 11:43
jschell1-Sep-11 11:43 
AnswerRe: Ms Access file Missing Pin
Eddy Vluggen3-Sep-11 10:55
professionalEddy Vluggen3-Sep-11 10:55 
AnswerRe: Ms Access file Missing Pin
kmoorevs9-Sep-11 12:25
kmoorevs9-Sep-11 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.