Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View & Trigger works just in QA

Status
Not open for further replies.

Moonrider

Programmer
Oct 30, 2001
12
0
0
BE
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 should probably add:

I am using MS SQL Server 2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top