Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, November 25, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: UPDATE Statement breaking Account AFTER DELETE Trigger
Giancarlo Villanueva
Posts: 8
 
UPDATE Statement breaking Account AFTER DELETE TriggerYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Dec 10 3:19 PM
fiogf49gjkf0d

I'm having difficulties with the UPDATE statement in my trigger.  The trigger is fired after DELETE on the sysdba.ACCOUNT table.  It INSERTs to an audit table that basically tracks deleted accounts.  There is a similar auditing table for changes to contacts, and I would like to update this table to reflect that its parent account has been deleted.



CREATE TRIGGER [sysdba].[tr_AccountDelete]<br /> ON [sysdba].[ACCOUNT]
AFTER DELETE
AS

IF @@ROWCOUNT > 0
BEGIN
    SET NOCOUNT ON
    DECLARE @Date DATETIME
    SET @Date = GETDATE()

    INSERT INTO Audits
    (id, table_name, date, row_deleted)
    SELECT  ACCOUNTID,
            'ACCOUNT',
            GETDATE(),
            'ACCOUNTID:' + acct.ACCOUNTID + ' ACCOUNT:' + ISNULL(acct.ACCOUNT, '') + ' MAINPHONE:' + ISNULL(acct.MAINPHONE, '')
    FROM DELETED AS acct;
   
    UPDATE ContactAudits
    SET parent_state = 'DELETED' WHERE parent_id IN (SELECT ACCOUNTID FROM DELETED)
END
SET NOCOUNT OFF


The INSERT statement should be free of errors.  As far as I can tell the UPDATE statement is the problem since the trigger will succeed without it.

[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: UPDATE Statement breaking Account AFTER DELETE TriggerYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Dec 10 4:35 PM
fiogf49gjkf0d

Aside from the fact that triggers are not supported by the SLX framework, I'm sure you'll appreciate that telling us you're 'having difficulties' is not really providing sufficient diagnostics.


I'd suggest that you try removing the semi-colon first.


I'd also suggest you look at the @Date variable: what is it for?


If that does not resolve it, please post the text of the error.

[Reply][Quote]
Giancarlo Villanueva
Posts: 8
 
Re: UPDATE Statement breaking Account AFTER DELETE TriggerYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 28 Dec 10 9:08 AM
fiogf49gjkf0d

I should elaborate on the source of the error.

Creating the trigger causes no problems; the problem arises during execution. When deleting an account, for instance, the account is not deleted.  This indicates that something has gone wrong during the execution of the trigger and SLX has rolled back the transaction.  I'm lead to believe that the UPDATE statement is the problem because when it is removed from the trigger, deletion proceeds merrily.  I don't know why it would have a problem with the UPDATE statement, but it seems to be the source of trouble.

Unfortunately, I've got no error text for you because SalesLogix doesn't provide any for this type of problem.  All I have to go on is trial and error.  I have a feeling that the problem is something I don't know about SLX or an obvious bug in my SQL that I'm overlooking.

Before my original post I tried with/without @Date and/or the semi-colon.

Thanks for any ideas you've got.


 


EDIT/UPDATE: It was indeed some obvious bug in my SQL, since I hadn't granted UPDATE permissions on the foreign table to sysdba.  I checked permissions before but glazed over adding UPDATE.  (frowny-face)

[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: UPDATE Statement breaking Account AFTER DELETE TriggerYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 28 Dec 10 12:53 PM
fiogf49gjkf0d

Oops! Ah well, got there in the end Smile

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/25/2024 6:06:17 PM