Ejecución de Trigger

14/05/2008 - 21:21 por Excequiel A. | Informe spam
Buenas tardes.

Actualmente tengo SqlServer 7 en una máquina con Sist. Operativo WK3, en
una tabla tengo un trigger de tipo insert, para cuando se inserte un
registro, realiza una actualización en otra tabla, el asunto es saber por
que razón puede fallar este trigger, sabiendo que la programación está bien
hecha, o ¿es imposible que falle?

atte.

EAM.

Preguntas similare

Leer las respuestas

#6 Excequiel A.
16/05/2008 - 21:31 | Informe spam
CREATE TRIGGER ActualizarBodega ON dbo.DetalleGuiaDespacho
FOR INSERT
AS
declare
@xpeso1 numeric(18,2),
@xcant1 int,
@xpeso2 numeric(18,2),
@xcant2 int,
@xpeso3 numeric(18,2),
@xcant3 int,
@xPesoEnvase1 numeric(18,2),
@xPesoEnvase2 numeric(18,2),
@xPesoEnvase3 numeric(18,2),
@xbdpeso1 numeric(18,2),
@xbdcant1 int,
@xbdpeso2 numeric(18,2),
@xbdcant2 int,
@xbdpeso3 numeric(18,2),
@xbdcant3 int,
@xbdPesoEnvase1 numeric(18,2),
@xbdPesoEnvase2 numeric(18,2),
@xbdPesoEnvase3 numeric(18,2),
@xPesoEvPaso numeric(18,2),
@xPesoPaso numeric(18,2),
@xCantPaso int,
@xCodEv1 int,
@xCodEv2 int,
@xCodEv3 int,
@xEv1 numeric(18,2),
@xEv2 numeric(18,2),
@xEv3 numeric(18,2)
set @xpeso1 = 0
set @xcant1 = 0
set @xpeso2 = 0
set @xcant2 = 0
set @xpeso3 = 0
set @xcant3 = 0
set @xPesoEnvase1 = 0
set @xPesoEnvase2 = 0
set @xPesoEnvase3 = 0
set @xbdpeso1 = 0
set @xbdcant1 = 0
set @xbdpeso2 = 0
set @xbdcant2 = 0
set @xbdpeso3 = 0
set @xbdcant3 = 0
set @xbdPesoEnvase1 = 0
set @xbdPesoEnvase2 = 0
set @xbdPesoEnvase3 = 0
set @xPesoEvPaso = 0
set @xPesoPaso = 0
set @xCantPaso = 0
set @xCodEv1 = 0
set @xCodEv2 = 0
set @xCodEv3 = 0
set @xEv1 = 0
set @xEv2 = 0
set @xEv3 = 0
if (select inse.dd_Boddestino from Inserted inse) > 0
begin
/* begin transaction Bod */
if (select count( Bs.Bd_lotes)
from Bodega Bs , Inserted ins
where (Bs.bd_Lotes=ins.dd_Lote) and
(Bs.bd_Variedad=ins.dd_codVariedad)and(bs.bd_Bodega=ins.dd_BodDestino))= 0
begin
Insert into Bodega
(BD_Peso1, BD_Cantidad1,BD_PesoEnvase1,
BD_Peso2, BD_Cantidad2, BD_PesoEnvase2,
BD_Peso3, BD_Cantidad3, BD_PesoEnvase3,
BD_CodEnvases1, BD_CodEnvases2, BD_CodEnvases3,
BD_CantidadStock, BD_CapacidadStock,
BD_Lotes, BD_Variedad, BD_Origen, BD_Proceso,
BD_Fecha, BD_CodSag,BD_Periodo, BD_CodUsuario,
BD_Bodega, BD_CodCliente, BD_TipoSemilla,
BD_CodPropietario, BD_Desinfeccion)
Select DD_KGtotal1, DD_Cantidad1, DD_Peso1,
DD_KGtotal2, DD_Cantidad2, DD_Peso2,
DD_KGtotal3, DD_Cantidad3, DD_Peso3,
DD_Envase1, DD_Envase2, DD_Envase3,
DD_Cantidad, DD_KgNeto,
DD_Lote, DD_CodVariedad, 'D', 'V',
getdate(),DD_CodSag, DD_Periodo, DD_CodUsuario,
DD_BodDestino,
DD_Codcliente, DD_CodTpoSem,
DD_CodPropietario, DD_Desinfeccion
from inserted
end
else
begin
select @xbdpeso1 = bd.bd_peso1,
@xbdcant1 = bd.bd_cantidad1,
@xbdpeso2 = bd.bd_peso2,
@xbdcant2 = bd.bd_cantidad2,
@xbdpeso3 = bd.bd_peso3,
@xbdcant3 = bd.bd_cantidad3,
@xbdPesoEnvase1 = bd.bd_PesoEnvase1,
@xbdPesoEnvase2 = bd.bd_PesoEnvase2,
@xbdPesoEnvase3 = bd.bd_PesoEnvase3
from bodega bd , Inserted ins
where (bd.bd_lotes=ins.dd_lote) and
(bd.bd_Variedad=ins.dd_codVariedad)and (bd.bd_Bodega=ins.dd_BodDestino)
select @xpeso1 = agr.Dd_KGtotal1,
@xcant1 = agr.Dd_cantidad1,
@xpeso2 = agr.Dd_KGtotal2,
@xcant2 = agr.Dd_cantidad2,
@xpeso3 = agr.Dd_KGtotal3,
@xcant3 = agr.Dd_cantidad3,
@xPesoEnvase1 = agr.DD_Peso1,
@xPesoEnvase2 = agr.Dd_Peso2,
@xPesoEnvase3 = agr.Dd_Peso3
from Inserted Agr
if (@xbdPesoEnvase1 > 0) begin
if (@xPesoEnvase1 <> @xBDPesoEnvase1) begin
if (@xPesoEnvase2 = @xBDPesoEnvase1) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if (@xPesoEnvase3 = @xBDPesoEnvase1) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
end
if (@xbdPesoEnvase2 > 0) begin
if (@xPesoEnvase2 <> @xBDPesoEnvase2) begin
if (@xPesoEnvase1 = @xBDPesoEnvase2) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if (@xPesoEnvase3 = @xBDPesoEnvase2) begin
set @xPesoEvPaso = @xPesoEnvase3
set @xPesoPaso = @xpeso3
set @xCantPaso = @xcant3
set @xPesoEnvase3 = @xPesoEnvase2
set @xpeso3 = @xpeso2
set @xcant3 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
end
end
end
if (@xbdPesoEnvase3 > 0) begin
if (@xPesoEnvase3 <> @xBDPesoEnvase3) begin
if (@xPesoEnvase1 = @xBDPesoEnvase3) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
else begin
if (@xPesoEnvase2 = @xBDPesoEnvase3) begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase3
set @xpeso2 = @xpeso3
set @xcant2 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
end
if @xPesoEnvase1 = 0
set @xpesoenvase1 = @xbdpesoenvase1
if @xPesoEnvase2 = 0
set @xpesoenvase2 = @xbdpesoenvase2
if @xPesoEnvase3 = 0
set @xpesoenvase3 = @xbdpesoenvase3
if (@xPesoEnvase1 <> @xbdpesoenvase1) begin
if @xbdpesoenvase2 = 0 begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if @xbdpesoenvase3 >= 0 begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
if (@xPesoEnvase2 <> @xbdpesoenvase2) and (@xbdpesoenvase2 > 0) begin
if @xbdpesoenvase1 = 0 begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase1
set @xpeso2 = @xpeso1
set @xcant2 = @xcant1
set @xPesoEnvase1 = @xPesoEvPaso
set @xpeso1 = @xPesoPaso
set @xcant1 = @xCantPaso
end
else begin
if @xbdpesoenvase3 >= 0 begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase3
set @xpeso2 = @xpeso3
set @xcant2 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
if (@xBdCant1 + @xcant1) >0
set @xEv1 = (@xBDPeso1 +@xpeso1)/(@xBDCant1 + @xcant1)
else
set @xEv1 = @xbdPesoEnvase1
if (@xBdCant2 + @xcant2) > 0
set @xEv2 = (@xBDPeso2 +@xpeso2)/(@xBDCant2 + @xcant2)
else
set @xEv2 = @xbdPesoEnvase2
if (@xBdCant3 + @xcant3) > 0
set @xEv3 = (@xBDPeso3 +@xpeso3)/(@xBDCant3 + @xcant3)
else
set @xEv3 = @xbdPesoEnvase3
update bodega
set
bd_CantidadStock = bd_Cantidadstock + @xcant1 + @xcant2 + @xcant3,
bd_CapacidadStock = bd_CapacidadStock + @xpeso1+@xpeso2+@xpeso3,
bd_PesoEnvase1 = @xev1,
bd_PesoEnvase2 = @xev2,
bd_PesoEnvase3 = @xev3,
bd_peso1 = bd_peso1 + @xpeso1,
bd_Cantidad1 = bd_Cantidad1 + @xcant1,
bd_peso2 = bd_peso2 + @xpeso2,
bd_Cantidad2 = bd_Cantidad2 + @xcant2,
bd_peso3 = bd_peso3 + @xpeso3,
bd_Cantidad3 = bd_Cantidad3 + @xcant3,
bd_codsag = inserted.dd_codsag
from inserted
where (bd_lotes = inserted.dd_lote) and
(bd_Variedad=inserted.dd_codVariedad) and (bd_Bodega=inserted.dd_BodDestino)
END
end


"Maxi" escribió en el mensaje
news:
Hola, podria poner aqui el codigo del trigger? si no fueron actualizados
es porque el trigger esta mal diseñado, no hay otra razon.


Salu2

Microsoft MVP SQL Server
Culminis Speaker
www.sqltotalconsulting.com

"Excequiel A." escribió en el mensaje
news:%
Sr. Maximiliano A.

La consulta en el trigger se ejecuta bien. La tabla pertenece a el
detalle de una guia, en
donde el trigger actualiza bodega. Es una actualización sencilla en la
cual
la guia contiene hasta diez registros y actualiza el campo del stock en
bodega, entonces todos los registros que fueron insertados para esta guia
que eran exactamente diez registros no fueron actualizados :-( bastante
preocupante.
La Deshabillitación del trigger, queda descartado por que ese mismo día y
con diferencia de 5 minutos se hicieron otras guias en las cuales sí se
actualizó bodega.
En ningun lugar del sistema cliente se usa la instrucción BCP.

atte.

EAM.

"Maxi Accotto" escribió en el mensaje
news:
Si la programacion esta bien hecha no puede fallar, ahora bien, usted no
indica la falla en si, que sucede? no se ejecuta? se ejecuta mal? si no
se
ejecuta puede ser (si esta bien programado) que lo hayan deshabilitado o
bien esten corriendo un proceso BCP y por defecto no los ejecuta


Microsoft MVP SQLServer
www.sqltotalconsulting.com
-

"Excequiel A." escribió en el mensaje de
noticias:
Buenas tardes.

Actualmente tengo SqlServer 7 en una máquina con Sist. Operativo WK3,
en
una tabla tengo un trigger de tipo insert, para cuando se inserte un
registro, realiza una actualización en otra tabla, el asunto es saber
por
que razón puede fallar este trigger, sabiendo que la programación está
bien hecha, o ¿es imposible que falle?

atte.

EAM.












Respuesta Responder a este mensaje
#7 Maxi
16/05/2008 - 22:02 | Informe spam
Lo que me imagine! a ver, los triggers no se ejecutan registro a registro
sino que en conjunto segun la instruccion, por ejemplo si en esa tabla se
inserta un solo registro el trigger que ustedes han diseñado funciona bien,
si se insertan mas de uno en la misma sentencia insert no va a funcionar el
trigger ya que esta mal diseñado.

Usted esta asignando variables al trigger y las variables pueden tener un
solo valor, entonces no esta pensado el trigger para trabajar con mas de un
registro por vez y puede hacer cualquier cosa.

Va a tener que hacer una reingenieria a ese trigger sacando las variables y
trajando con conjuntos de datos usando inserted y deleted en conjunto con
update


Salu2

Microsoft MVP SQL Server
Culminis Speaker
www.sqltotalconsulting.com

"Excequiel A." escribió en el mensaje
news:%
CREATE TRIGGER ActualizarBodega ON dbo.DetalleGuiaDespacho
FOR INSERT
AS
declare
@xpeso1 numeric(18,2),
@xcant1 int,
@xpeso2 numeric(18,2),
@xcant2 int,
@xpeso3 numeric(18,2),
@xcant3 int,
@xPesoEnvase1 numeric(18,2),
@xPesoEnvase2 numeric(18,2),
@xPesoEnvase3 numeric(18,2),
@xbdpeso1 numeric(18,2),
@xbdcant1 int,
@xbdpeso2 numeric(18,2),
@xbdcant2 int,
@xbdpeso3 numeric(18,2),
@xbdcant3 int,
@xbdPesoEnvase1 numeric(18,2),
@xbdPesoEnvase2 numeric(18,2),
@xbdPesoEnvase3 numeric(18,2),
@xPesoEvPaso numeric(18,2),
@xPesoPaso numeric(18,2),
@xCantPaso int,
@xCodEv1 int,
@xCodEv2 int,
@xCodEv3 int,
@xEv1 numeric(18,2),
@xEv2 numeric(18,2),
@xEv3 numeric(18,2)
set @xpeso1 = 0
set @xcant1 = 0
set @xpeso2 = 0
set @xcant2 = 0
set @xpeso3 = 0
set @xcant3 = 0
set @xPesoEnvase1 = 0
set @xPesoEnvase2 = 0
set @xPesoEnvase3 = 0
set @xbdpeso1 = 0
set @xbdcant1 = 0
set @xbdpeso2 = 0
set @xbdcant2 = 0
set @xbdpeso3 = 0
set @xbdcant3 = 0
set @xbdPesoEnvase1 = 0
set @xbdPesoEnvase2 = 0
set @xbdPesoEnvase3 = 0
set @xPesoEvPaso = 0
set @xPesoPaso = 0
set @xCantPaso = 0
set @xCodEv1 = 0
set @xCodEv2 = 0
set @xCodEv3 = 0
set @xEv1 = 0
set @xEv2 = 0
set @xEv3 = 0
if (select inse.dd_Boddestino from Inserted inse) > 0
begin
/* begin transaction Bod */
if (select count( Bs.Bd_lotes)
from Bodega Bs , Inserted ins
where (Bs.bd_Lotes=ins.dd_Lote) and
(Bs.bd_Variedad=ins.dd_codVariedad)and(bs.bd_Bodega=ins.dd_BodDestino))= 0
begin
Insert into Bodega
(BD_Peso1, BD_Cantidad1,BD_PesoEnvase1,
BD_Peso2, BD_Cantidad2, BD_PesoEnvase2,
BD_Peso3, BD_Cantidad3, BD_PesoEnvase3,
BD_CodEnvases1, BD_CodEnvases2, BD_CodEnvases3,
BD_CantidadStock, BD_CapacidadStock,
BD_Lotes, BD_Variedad, BD_Origen, BD_Proceso,
BD_Fecha, BD_CodSag,BD_Periodo, BD_CodUsuario,
BD_Bodega, BD_CodCliente, BD_TipoSemilla,
BD_CodPropietario, BD_Desinfeccion)
Select DD_KGtotal1, DD_Cantidad1, DD_Peso1,
DD_KGtotal2, DD_Cantidad2, DD_Peso2,
DD_KGtotal3, DD_Cantidad3, DD_Peso3,
DD_Envase1, DD_Envase2, DD_Envase3,
DD_Cantidad, DD_KgNeto,
DD_Lote, DD_CodVariedad, 'D', 'V',
getdate(),DD_CodSag, DD_Periodo, DD_CodUsuario,
DD_BodDestino,
DD_Codcliente, DD_CodTpoSem,
DD_CodPropietario, DD_Desinfeccion
from inserted
end
else
begin
select @xbdpeso1 = bd.bd_peso1,
@xbdcant1 = bd.bd_cantidad1,
@xbdpeso2 = bd.bd_peso2,
@xbdcant2 = bd.bd_cantidad2,
@xbdpeso3 = bd.bd_peso3,
@xbdcant3 = bd.bd_cantidad3,
@xbdPesoEnvase1 = bd.bd_PesoEnvase1,
@xbdPesoEnvase2 = bd.bd_PesoEnvase2,
@xbdPesoEnvase3 = bd.bd_PesoEnvase3
from bodega bd , Inserted ins
where (bd.bd_lotes=ins.dd_lote) and
(bd.bd_Variedad=ins.dd_codVariedad)and (bd.bd_Bodega=ins.dd_BodDestino)
select @xpeso1 = agr.Dd_KGtotal1,
@xcant1 = agr.Dd_cantidad1,
@xpeso2 = agr.Dd_KGtotal2,
@xcant2 = agr.Dd_cantidad2,
@xpeso3 = agr.Dd_KGtotal3,
@xcant3 = agr.Dd_cantidad3,
@xPesoEnvase1 = agr.DD_Peso1,
@xPesoEnvase2 = agr.Dd_Peso2,
@xPesoEnvase3 = agr.Dd_Peso3
from Inserted Agr
if (@xbdPesoEnvase1 > 0) begin
if (@xPesoEnvase1 <> @xBDPesoEnvase1) begin
if (@xPesoEnvase2 = @xBDPesoEnvase1) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if (@xPesoEnvase3 = @xBDPesoEnvase1) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
end
if (@xbdPesoEnvase2 > 0) begin
if (@xPesoEnvase2 <> @xBDPesoEnvase2) begin
if (@xPesoEnvase1 = @xBDPesoEnvase2) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if (@xPesoEnvase3 = @xBDPesoEnvase2) begin
set @xPesoEvPaso = @xPesoEnvase3
set @xPesoPaso = @xpeso3
set @xCantPaso = @xcant3
set @xPesoEnvase3 = @xPesoEnvase2
set @xpeso3 = @xpeso2
set @xcant3 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
end
end
end
if (@xbdPesoEnvase3 > 0) begin
if (@xPesoEnvase3 <> @xBDPesoEnvase3) begin
if (@xPesoEnvase1 = @xBDPesoEnvase3) begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
else begin
if (@xPesoEnvase2 = @xBDPesoEnvase3) begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase3
set @xpeso2 = @xpeso3
set @xcant2 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
end
if @xPesoEnvase1 = 0
set @xpesoenvase1 = @xbdpesoenvase1
if @xPesoEnvase2 = 0
set @xpesoenvase2 = @xbdpesoenvase2
if @xPesoEnvase3 = 0
set @xpesoenvase3 = @xbdpesoenvase3
if (@xPesoEnvase1 <> @xbdpesoenvase1) begin
if @xbdpesoenvase2 = 0 begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase2
set @xpeso1 = @xpeso2
set @xcant1 = @xcant2
set @xPesoEnvase2 = @xPesoEvPaso
set @xpeso2 = @xPesoPaso
set @xcant2 = @xCantPaso
end
else begin
if @xbdpesoenvase3 >= 0 begin
set @xPesoEvPaso = @xPesoEnvase1
set @xPesoPaso = @xpeso1
set @xCantPaso = @xcant1
set @xPesoEnvase1 = @xPesoEnvase3
set @xpeso1 = @xpeso3
set @xcant1 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
if (@xPesoEnvase2 <> @xbdpesoenvase2) and (@xbdpesoenvase2 > 0) begin
if @xbdpesoenvase1 = 0 begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase1
set @xpeso2 = @xpeso1
set @xcant2 = @xcant1
set @xPesoEnvase1 = @xPesoEvPaso
set @xpeso1 = @xPesoPaso
set @xcant1 = @xCantPaso
end
else begin
if @xbdpesoenvase3 >= 0 begin
set @xPesoEvPaso = @xPesoEnvase2
set @xPesoPaso = @xpeso2
set @xCantPaso = @xcant2
set @xPesoEnvase2 = @xPesoEnvase3
set @xpeso2 = @xpeso3
set @xcant2 = @xcant3
set @xPesoEnvase3 = @xPesoEvPaso
set @xpeso3 = @xPesoPaso
set @xcant3 = @xCantPaso
end
end
end
if (@xBdCant1 + @xcant1) >0
set @xEv1 = (@xBDPeso1 +@xpeso1)/(@xBDCant1 + @xcant1)
else
set @xEv1 = @xbdPesoEnvase1
if (@xBdCant2 + @xcant2) > 0
set @xEv2 = (@xBDPeso2 +@xpeso2)/(@xBDCant2 + @xcant2)
else
set @xEv2 = @xbdPesoEnvase2
if (@xBdCant3 + @xcant3) > 0
set @xEv3 = (@xBDPeso3 +@xpeso3)/(@xBDCant3 + @xcant3)
else
set @xEv3 = @xbdPesoEnvase3
update bodega
set
bd_CantidadStock = bd_Cantidadstock + @xcant1 + @xcant2 + @xcant3,
bd_CapacidadStock = bd_CapacidadStock + @xpeso1+@xpeso2+@xpeso3,
bd_PesoEnvase1 = @xev1,
bd_PesoEnvase2 = @xev2,
bd_PesoEnvase3 = @xev3,
bd_peso1 = bd_peso1 + @xpeso1,
bd_Cantidad1 = bd_Cantidad1 + @xcant1,
bd_peso2 = bd_peso2 + @xpeso2,
bd_Cantidad2 = bd_Cantidad2 + @xcant2,
bd_peso3 = bd_peso3 + @xpeso3,
bd_Cantidad3 = bd_Cantidad3 + @xcant3,
bd_codsag = inserted.dd_codsag
from inserted
where (bd_lotes = inserted.dd_lote) and
(bd_Variedad=inserted.dd_codVariedad) and
(bd_Bodega=inserted.dd_BodDestino)
END
end


"Maxi" escribió en el mensaje
news:
Hola, podria poner aqui el codigo del trigger? si no fueron actualizados
es porque el trigger esta mal diseñado, no hay otra razon.


Salu2

Microsoft MVP SQL Server
Culminis Speaker
www.sqltotalconsulting.com

"Excequiel A." escribió en el mensaje
news:%
Sr. Maximiliano A.

La consulta en el trigger se ejecuta bien. La tabla pertenece a el
detalle de una guia, en
donde el trigger actualiza bodega. Es una actualización sencilla en la
cual
la guia contiene hasta diez registros y actualiza el campo del stock en
bodega, entonces todos los registros que fueron insertados para esta
guia
que eran exactamente diez registros no fueron actualizados :-( bastante
preocupante.
La Deshabillitación del trigger, queda descartado por que ese mismo día
y con diferencia de 5 minutos se hicieron otras guias en las cuales sí
se actualizó bodega.
En ningun lugar del sistema cliente se usa la instrucción BCP.

atte.

EAM.

"Maxi Accotto" escribió en el mensaje
news:
Si la programacion esta bien hecha no puede fallar, ahora bien, usted
no
indica la falla en si, que sucede? no se ejecuta? se ejecuta mal? si no
se
ejecuta puede ser (si esta bien programado) que lo hayan deshabilitado
o
bien esten corriendo un proceso BCP y por defecto no los ejecuta


Microsoft MVP SQLServer
www.sqltotalconsulting.com
-

"Excequiel A." escribió en el mensaje de
noticias:
Buenas tardes.

Actualmente tengo SqlServer 7 en una máquina con Sist. Operativo WK3,
en
una tabla tengo un trigger de tipo insert, para cuando se inserte un
registro, realiza una actualización en otra tabla, el asunto es saber
por
que razón puede fallar este trigger, sabiendo que la programación está
bien hecha, o ¿es imposible que falle?

atte.

EAM.
















email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una pregunta AnteriorRespuesta Tengo una respuesta
Search Busqueda sugerida