HelpSpot How to delete filter from other users (sql admin)

Author Johnny Josefsson on January 18, 2012 | Print | Bookmark
To delete filter from other user is for the moment only available through the
SQL server. The reason for wanting this could be several reasons, to scenarions
from the real world:

- A user has created a huge filter which crash the instance once they logon to
  their account
- Clean up all users filter when upgrading from version 2 to version 3 where
  you use permissions groups to show filteers

COPY PASTE TO your SQL Management Console (Microsoft SQL Server) or Workbench
CE Console (MySQL), from the correct section below


--------------------------------------
Microsoft SQL Server
--------------------------------------
DECLARE @staff NVARCHAR(100)
DECLARE @staffid INT, @filters INT, @filters2 INT

/*   write the email of the staff  */
SET @staff = 'user@domain.top'
/*   write the email of the staff  */

SELECT @staffid = xPerson FROM HS_Person WHERE sEmail = @staff

IF @staffid is not null
BEGIN
  PRINT 'Found staff with that email addressing. Starting to delete the staffs filters...'
  SELECT @filters = COUNT(xFilter) FROM HS_Filters WHERE xPerson = @staffid
    IF @filters = 0
    BEGIN
      PRINT 'Found no filters for the staff to delete. Aborting...'
    END
    ELSE
    BEGIN
      DELETE FROM HS_Filters WHERE xPerson = @staffid
/* uncomment if you run Helpspot V3
        SELECT @filters2 = COUNT(xFilter) FROM HS_Filter_People WHERE xPerson = @staffid
  IF @filters2 = 0
  BEGIN
   DELETE FROM HS_Filter_Person WHERE xPerson = @staffid
  END
*/      
      PRINT 'Deleted ' + CONVERT(nvarchar(4), @filters) +' filters from the specified staff.'
    END
END
ELSE
BEGIN
  PRINT 'Could not find staff with that e-mail address. Aborting...'
END

--------------------------------------


--------------------------------------
MySQL Server
--------------------------------------
The flavour of MySQL was to different at the momemnt, the syntax was
not at all the same and you can only DECLARE inside a
BEGIN / END clause

but will write one later on... perhaps... as it's not needed any more

sorry for not having comments on as it only gets spammed, no captcha in
this KB software, gonna need to change in future perhaps....
--------------------------------------

Was this article helpful?

Yes No

Category: HelpSpot

Last updated on March 8, 2012 with 1183 views