E-fatura Seri Kontrolü – Trigger

CREATE TRIGGER [dbo].INN_TR_EBELGE_SERISI_KONTROLU ON [dbo].TBLFATUIRS FOR INSERT
AS
BEGIN

DECLARE @KAYIT INT, @ACIKLAMA NVARCHAR(100), @BELGE_NO NVARCHAR(15), @SUBE_KODU INT, @FTIRSIP CHAR(1)
SELECT @BELGE_NO = FATIRS_NO, @SUBE_KODU=SUBE_KODU, @FTIRSIP = FTIRSIP FROM INSERTED
IF @FTIRSIP = '1'
BEGIN

IF ( LEFT(@BELGE_NO,3) NOT IN ( SELECT SERI FROM TBLEFATUNO WITH (NOLOCK) WHERE SERI IS NOT NULL UNION ALL SELECT SERI FROM TBLEFATSERI WITH (NOLOCK) WHERE SERI IS NOT NULL ) )

BEGIN
RAISERROR('E-FATURA, E-ARSIV SERISINDEN KAYIT YAPMALISINIZ',16,1)
ROLLBACK TRANSACTION
END
END

END