Hi!
I wrote this trigger on a view to write the data
into two different tables :
Don't worry about the strange field and tab-names
and the print-statements: IT'S GERMAN
CREATE TRIGGER vieRechnung_Ins ON dbo.vieRechnung
INSTEAD OF INSERT
AS
SET NOCOUNT ON
DECLARE @Nr VarChar(12)
DECLARE @Datum SmallDateTime
DECLARE @AuftragsNr VarChar(12)
DECLARE @Zahlungsbedingung VarChar(50)
DECLARE @Skonto Decimal(18,2)
PRINT 'SELECT AUF INSERTED'
SELECT @Nr = Nr, @Datum = Datum, @AuftragsNr = AuftragsNr,
@Zahlungsbedingung = Zahlungsbedingung,
@Skonto = Skonto
FROM INSERTED
PRINT ''
PRINT 'ABFRAGE OB Zahlungsbedingung EXISTIERT'
PRINT '+ EVENTUELLES EINFÜGEN'
DECLARE @ZahlungsID Int
SELECT @ZahlungsID = NULL
IF @Zahlungsbedingung IS NOT Null
BEGIN
IF NOT EXISTS (SELECT [Text] FROM tabZahlungsbedingungen
WHERE [Text] = @Zahlungsbedingung)
INSERT INTO tabZahlungsbedingungen ([Text], Skonto)
VALUES (@Zahlungsbedingung, @Skonto)
PRINT ''
PRINT 'SUCHT ZahlungsID'
SELECT @ZahlungsID = ZahlungsID
FROM tabZahlungsbedingungen
WHERE [Text] = @Zahlungsbedingung
END
PRINT ''
PRINT 'ZahlungsID:'
PRINT CAST(@ZahlungsID AS VARCHAR(20))
PRINT ''
PRINT 'SCHREIBT IN tabRechnung'
INSERT INTO tabRechnung (Nr, Datum, AuftragsNr, ZahlungsID)
VALUES (@Nr, @Datum, @AuftragsNr, @ZahlungsID)
It runs perfect but just in QA
not in EM or Visual Basic
the error in EM says: "Error 5: EXCEPTION_ACCESS_VIOLATION"
if I add a record in EM it just writes the record to the
"tabRechnung"-Table but not to the "tabZahlungsbedingungen"-Table
but in QA it works perfectly.
Can anyone help?
I wrote this trigger on a view to write the data
into two different tables :
Don't worry about the strange field and tab-names
and the print-statements: IT'S GERMAN
CREATE TRIGGER vieRechnung_Ins ON dbo.vieRechnung
INSTEAD OF INSERT
AS
SET NOCOUNT ON
DECLARE @Nr VarChar(12)
DECLARE @Datum SmallDateTime
DECLARE @AuftragsNr VarChar(12)
DECLARE @Zahlungsbedingung VarChar(50)
DECLARE @Skonto Decimal(18,2)
PRINT 'SELECT AUF INSERTED'
SELECT @Nr = Nr, @Datum = Datum, @AuftragsNr = AuftragsNr,
@Zahlungsbedingung = Zahlungsbedingung,
@Skonto = Skonto
FROM INSERTED
PRINT ''
PRINT 'ABFRAGE OB Zahlungsbedingung EXISTIERT'
PRINT '+ EVENTUELLES EINFÜGEN'
DECLARE @ZahlungsID Int
SELECT @ZahlungsID = NULL
IF @Zahlungsbedingung IS NOT Null
BEGIN
IF NOT EXISTS (SELECT [Text] FROM tabZahlungsbedingungen
WHERE [Text] = @Zahlungsbedingung)
INSERT INTO tabZahlungsbedingungen ([Text], Skonto)
VALUES (@Zahlungsbedingung, @Skonto)
PRINT ''
PRINT 'SUCHT ZahlungsID'
SELECT @ZahlungsID = ZahlungsID
FROM tabZahlungsbedingungen
WHERE [Text] = @Zahlungsbedingung
END
PRINT ''
PRINT 'ZahlungsID:'
PRINT CAST(@ZahlungsID AS VARCHAR(20))
PRINT ''
PRINT 'SCHREIBT IN tabRechnung'
INSERT INTO tabRechnung (Nr, Datum, AuftragsNr, ZahlungsID)
VALUES (@Nr, @Datum, @AuftragsNr, @ZahlungsID)
It runs perfect but just in QA
not in EM or Visual Basic
the error in EM says: "Error 5: EXCEPTION_ACCESS_VIOLATION"
if I add a record in EM it just writes the record to the
"tabRechnung"-Table but not to the "tabZahlungsbedingungen"-Table
but in QA it works perfectly.
Can anyone help?