SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

IF OBJECT_ID ('FATURA_TRG_EFATURA_IPTAL', 'TR') IS NOT NULL
ALTER TABLE [dbo].[FATURA] DISABLE TRIGGER [FATURA_TRG_EFATURA_IPTAL]
GO

IF OBJECT_ID ('FATURA_TRG_EFATURA_IPTAL', 'TR') IS NOT NULL
  DROP TRIGGER FATURA_TRG_EFATURA_IPTAL
GO

 CREATE TRIGGER [dbo].[FATURA_TRG_EFATURA_IPTAL] ON [dbo].[FATURA] FOR UPDATE AS
 BEGIN   
   DECLARE @FATID INT, @EFATURADURUM INT, @EDEVLETDURUM INT
   SELECT  @FATID=FATID, @EFATURADURUM=ISNULL(EFATURADURUM,0),@EDEVLETDURUM = ISNULL( EDEVLETDURUM, 0 ) FROM inserted
           SET NOCOUNT ON;

           IF (@EFATURADURUM=5) OR ((@EDEVLETDURUM = 2) AND (@EFATURADURUM=7))
           BEGIN
             UPDATE FATURA SET FIPTAL=1,UNVANI=case when left(UNVANI,9) <> 'Ý P T A L' then 'Ý P T A L '+UNVANI else UNVANI end WHERE FATID=@FATID
           END
        END
/* Ver No:1  Created by S at 25.03.2013 12:01:04 */
GO

IF OBJECT_ID ('FATURA_TRG_EFATURA_IPTAL', 'TR') IS NOT NULL
ALTER TABLE [dbo].[FATURA] ENABLE TRIGGER [FATURA_TRG_EFATURA_IPTAL]
GO

