SQL Script to delete stranded activity for a specific user

Hi all

In this article I am providing a script to delete the activity table records for a specific stranded user in Dynamics GP. This will enable us not to have all the users log out of GP in order to execute these scripts. This is typically handy when we have many users signed into the system from various regions and its a tough job to have all the users sign off the system for this maintenance to be done.

Note: Its always advisable to take a back up of the DYNAMICS database before you execute this script. :)

DECLARE @USERID CHAR(15)
DECLARE @CMPNYNAM CHAR(30)
 
SET @USERID = 'testuser'
SET @CMPNYNAM = 'Fabrikam, Inc.'
 
/*Deleting the user record from the DEX_LOCK table*/
DELETE  FROM tempdb.dbo.DEX_LOCK
WHERE   session_id = ( SELECT   SQLSESID
                       FROM     DYNAMICS.dbo.ACTIVITY
                       WHERE    USERID = @USERID
                                AND CMPNYNAM = RTRIM(@CMPNYNAM)
                     )
 
/*Deleting the user record from the DEX_SESSION table*/
DELETE  FROM tempdb.dbo.DEX_SESSION
WHERE   session_id = ( SELECT   SQLSESID
                       FROM     DYNAMICS.dbo.ACTIVITY
                       WHERE    USERID = @USERID
                                AND CMPNYNAM = RTRIM(@CMPNYNAM)
                     )
 
/*Deleting the user record from the SY00801 table*/
DELETE  FROM DYNAMICS.dbo.SY00801
WHERE   USERID = @USERID
        AND CMPANYID = ( SELECT CMPANYID
                         FROM   DYNAMICS.dbo.SY01500
                         WHERE  CMPNYNAM = RTRIM(@CMPNYNAM)
                       )
 
/*Deleting the user record from the SY00800 table*/
DELETE  FROM DYNAMICS.dbo.SY00800
WHERE   USERID = @USERID
        AND CMPNYNAM = RTRIM(@CMPNYNAM)
 
/*Deleting the user record from the ACTIVITY table*/
DELETE  FROM DYNAMICS.dbo.ACTIVITY
WHERE   USERID = @USERID
        AND CMPNYNAM = RTRIM(@CMPNYNAM)

I hope this script above would be useful to you folks…

Until next post…

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)

May 16, 2010 · veeyeskay · 5 Comments
Tags: , , , , , , ,  Â· Posted in: Dynamics, Great Plains, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, System Total Views: 1,443

  • http://rldu.wordpress.com Ron Wilson

    Ha…need to read the script a little closer. I now see the 4 lines where you declare and set your variables :) . Nice script.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
    • veeyeskay

      No problem. :) Hope you find this script helpful… :)

      VA:F [1.9.13_1145]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.13_1145]
      Rating: 0 (from 0 votes)
  • veeyeskay

    This script ideally only removes the activity records for the specific user-company activity record that has been stranded. All activities for other users are intact.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • http://rldu.wordpress.com Ron Wilson

    So what happens if users are active in GP when you run this script?

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • Pingback: SQL Script to delete stranded activity for a specific user - DynamicAccounting.net