Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/09/2015, 12:17
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Problema Rollback, Commit Transaction SQL server

y si movemos el begin try de lugar???

Código SQL:
Ver original
  1. PROCEDURE [dbo].[addPosAndStore]
  2. @idStrClient AS VARCHAR(50),
  3. @statusList AS text,
  4. @nameList AS text,
  5. @posidList AS text,
  6. @nodesList AS text,
  7. @msg AS VARCHAR(200) output
  8. AS
  9. BEGIN
  10.     SET NOCOUNT ON
  11.     DECLARE @idClient BIGINT,
  12.              @idConstraint BIGINT,
  13.              @posidConstraint BIGINT,
  14.              @name  VARCHAR(100),
  15.              @posId  VARCHAR(100),
  16.              @businessIdNode  VARCHAR(100),
  17.              @STATUS tinyint,
  18.              @totalRows INT,
  19.              @counter INT,
  20.              @idHd BIGINT,
  21.              @idHierarchyData BIGINT,
  22.              @retValue INT
  23.      BEGIN TRANSACTION  Tadd                
  24.      BEGIN TRY      
  25.         SELECT * INTO #tstatus FROM Split(@statusList,',')
  26.         SELECT * INTO #tname FROM Split(@nameList,',')
  27.         SELECT * INTO #posid FROM Split(@posidList,',')
  28.         SELECT * INTO #nodes FROM Split(@nodesList,',')
  29.            
  30.         SET @totalRows = (SELECT COUNT(*) FROM #tstatus)
  31.         SET @counter = 0    
  32.         WHILE @counter <= @totalRows      
  33.         BEGIN      
  34.             SET @STATUS = CONVERT(TINYINT,(SELECT VALUE FROM #tstatus WHERE id = @counter))
  35.             SET @name = (SELECT VALUE FROM #tname WHERE id = @counter)
  36.             SET @posId = (SELECT VALUE FROM #posid WHERE id = @counter)
  37.             SET @businessIdNode = (SELECT VALUE FROM #nodes WHERE id = @counter)            
  38.             SET @idClient = (SELECT id FROM Client WHERE idStrClient = @idStrClient)
  39.  
  40.             EXEC   @retValue = [dbo].[addStore]
  41.                     @name = @name,
  42.                     @businessIdNode = @businessIdNode,
  43.                     @idClient = @idClient,
  44.                     @idHd = @idHd OUTPUT,
  45.                     @msg =  @msg output
  46.                        
  47.             SET @idHierarchyData = (SELECT @idHd)
  48.            
  49.             IF @idHierarchyData = -1 OR  @idHierarchyData IS NULL          
  50.                 RETURN              
  51.            
  52.             INSERT INTO TableConstraint (openingSchedule, closingSchedule,salesLimitByDay,salesAmountByDay,salesLimitByMonth,salesAmountByMonth) VALUES (NULL, NULL, 0.0, 0, 0.0, 0)
  53.             SET @posidConstraint =  (SELECT MAX(id) FROM TxnConstraint)
  54.            
  55.             INSERT INTO [POS]
  56.                    ([idClient],[idHierarchyData],[POSIdentifier],[TYPE],[STATUS],[idConstraint])
  57.              VALUES
  58.                    (@idClient,@idHierarchyData,@posId,0,@STATUS,@posidConstraint)                  
  59.                    SET @counter = @counter + 1                      
  60.         END                        
  61.         DROP TABLE #tname
  62.         DROP TABLE #tstatus
  63.         DROP TABLE #posid
  64.                                                    
  65.         COMMIT TRANSACTION Tadd
  66.         SET @msg = '00,Se han insertado los registros correctamente'
  67.     END TRY
  68.     BEGIN CATCH
  69.         SET @msg = '99,Ocurrio un Error: '+ERROR_MESSAGE()+' en la línea ' + CONVERT(NVARCHAR(255), ERROR_LINE() ) + '.'
  70.         ROLLBACK TRANSACTION Tadd
  71.     END CATCH
  72. END
  73. GO


http://stackoverflow.com/questions/1...l-server-2008\
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me