Ver Mensaje Individual
  #1  
Antiguo 28-04-2017
LIGERO LIGERO is offline
Miembro
 
Registrado: jun 2007
Posts: 42
Reputación: 0
LIGERO Va por buen camino
Modificar campo al insertar registro

Buenas:

Estoy haciendo un trigger para cuando se inserta un registro en una base de datos, modificar uno de los campos de dicho registro.


Primera opción que no funciona

Código SQL [-]

USE [G001]
GO
/****** Object:  Trigger [dbo].[mapeoweb]    Script Date: 04/28/2017 10:43:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[mapeoweb]
ON [dbo].[INCIDENCIASLIN]
FOR INSERT
AS


BEGIN

  SET NOCOUNT ON

  if (comentario like '%MRW%')
    totalcliente=totalcliente / 1.21
       
END



Esta opción funciona, pero realiza el cambio en todos los registros de la tabla implicados en la clausula where

Código SQL [-]

USE [G001]
GO
/****** Object:  Trigger [dbo].[mapeoweb]    Script Date: 04/28/2017 10:43:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[mapeoweb]
ON [dbo].[INCIDENCIASLIN]
FOR INSERT
AS


BEGIN

  SET NOCOUNT ON

update incidenciaslin
set totalcliente=totalcliente / 1.21    
WHERE comentario like '%MRW%' and codarticulo<=0

update incidenciaslin
set codarticulo=9586  
WHERE comentario like '%MRW%' 


update incidenciaslin
set codarticulo=22175,
  UDSCLI1=1,
  UDSCLI2=1,
  UDSCLI3=1,
  UDSCLI4=1, 
  totalcliente=2.5
WHERE comentario like '%MegaReembolso%' 

END



Muchas gracias y espero poder solucionar el problema con vuestra ayuda.
Responder Con Cita