Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Borislav Borissov
  Where is Borislav Borissov?
 Sofia
 Bulgaria
 Borislav Borissov
 To: Frank Cazabon
  Where is Frank Cazabon?
 
 Trinidad And Tobago
 Frank Cazabon
Subject: RE: VFPMSSQL Stored Procedures and Triggers
Thread ID: 170432 Message ID: 170482 # Views: 1 # Ratings: 0
Version: Not Applicable Category: Databases, Tables and SQL Server
Date: Tuesday, April 29, 2008 10:08:02 PM         
   



> > I forgot to JOIN tables:
>
> Yes, I picked that up as well, but I now get another error(s) with this code:
>
>
> CREATE TRIGGER Trig_PaymentsDetails 
> ON PaymentsDetails
>        FOR UPDATE, DELETE, INSERT
> AS
>  BEGIN
>      UPDATE Sales
>            SET nBalance = nBalance + Tbl1.Amount
>      FROM Sales
>      INNER JOIN (SELECT iSaleid, SUM(nAmount) AS Amount
>                         FROM (SELECT iSaleid, -nAmount
>                                      FROM INSERTED
>                               UNION ALL 
>                               SELECT iSaleid, nAmount
>                                      FROM DELETED) Tbl2
>                  GROUP BY iSaleid) Tbl1
> 		on Sales.iSaleid = Tbl1.iSaleid
> 
>      IF @@ERROR <> 0
>         ROLLBACK TRANSACTION
> 
>  END
> 

>
>

> Msg 8155, Level 16, State 2, Procedure Trig_PaymentsDetails, Line 11
> No column was specified for column 2 of 'Tbl2'.
> Msg 207, Level 16, State 1, Procedure Trig_PaymentsDetails, Line 14
> Invalid column name 'nAmount'.
>

>
> neither of which make any sense to me :-(
>
>
> The problem was -nAmount as a field name, I switched the UNION ALL so that I select from the Deleted table first, or I could have used an AS nAmount instead.
>
> Frank.
>
> Frank Cazabon
> Samaan Systems Ltd.
> www.SamaanSystems.com/

Grrrr :-)
....
(SELECT iSaleid, -nAmount AS nAmount
       FROM INSERTED
UNION ALL 
SELECT iSaleid, nAmount AS nAmount
       FROM DELETED) Tbl2
....

-----------------
Borislav Borissov

Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.

ENTIRE THREAD

VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 7:33:25 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 8:03:20 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 8:18:57 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 9:06:40 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 9:16:26 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 9:31:54 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 9:36:38 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 9:43:35 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 9:49:39 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 9:57:35 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 10:08:02 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 10:20:51 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 10:37:51 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Frank Cazabon @ 4/29/2008 8:57:02 PM
RE: VFPMSSQL Stored Procedures and Triggers Posted by Borislav Borissov @ 4/29/2008 9:11:51 PM