Hi there. I have this query:DECLARE Cursore CURSOR FOR SELECT * FROM diegotempDECLARE @Company AS VARCHAR(100)DECLARE @Address1 AS VARCHAR(100)DECLARE @Address2 AS VARCHAR(100)DECLARE @Address3 AS VARCHAR(100)DECLARE @County AS VARCHAR(100)DECLARE @PostCode AS VARCHAR(100)DECLARE @BusinessPhone AS NVARCHAR(100)DECLARE @ConfettiRegion AS VARCHAR(100)DECLARE @TownCounty INTDECLARE @cpCompanyID INTDECLARE @BranchID INTDECLARE @intErrorCode INTDECLARE @numberRows INTOPEN CursoreFETCH NEXT FROM Cursore INTO @Company, @Address1, @Address2, @Address3, @County, @PostCode, @BusinessPhone, @ConfettiRegionBEGIN TRANWHILE @@FETCH_STATUS = 0BEGIN INSERT INTO cpCompany(Name) VALUES (@Company) SET @cpCompanyID=(SELECT @@IDENTITY) SELECT @intErrorCode = @@ERROR IF (@intErrorCode <> 0) GOTO PROBLEM SET @numberRows = @@ROWCOUNT PRINT @numberRows INSERT INTO cpBranch(CompanyID,Name,WhenUpdated,WhenCreated) VALUES (@cpCompanyID,@Company,'01/01/1900 00:00:00','01/01/1900 00:00:00') SET @BranchID=(SELECT @@IDENTITY) SELECT @intErrorCode = @@ERROR IF (@intErrorCode <> 0) GOTO PROBLEM SET @TownCounty=(SELECT id FROM geArea WHERE name = @county) INSERT INTO cpBranchInfo(BranchID,AddressLine1,AddressLine2,AddressLine3,PostalCode,County,Country,Telephone) VALUES (@BranchID,@Address1,@Address2,@Address3,@PostCode,@TownCounty,'222',@BusinessPhone) SELECT @intErrorCode = @@ERROR IF (@intErrorCode <> 0) GOTO PROBLEM FETCH NEXT FROM Cursore INTO @Company, @Address1, @Address2, @Address3, @County, @PostCode, @BusinessPhone, @ConfettiRegionENDCOMMIT TRANPROBLEM:IF (@intErrorCode <> 0) BEGINPRINT 'Unexpected error occurred!' ROLLBACK TRANENDCLOSE CursoreDEALLOCATE Cursore
Which basically take some infos from a temp table (diegotemp), and put them in the appropriate ones. I have a problem, the rollback seems to do not work correctly, can you help me please?Thanks. Diego.