====== {$page} ====== ===== Explanation of SQL ===== This SQL will query the database and delete any Scheduled Macro Activities that are no longer associated with a Recurring Activity. ===== Steps to Delete a Recurring Activity ===== - Create a **Backup.** - Open **Control** - Click on **Sales and Marketing** - Click on **Recurring Activities** - Click on any **Recurring Activity** you want to remove. - Click on the **Delete** button on the right side toolbar. Confirm any prompts to complete the deletion of the recurring activity. - As a final step, any scheduled activities may need to be manually deleted if they still appear on the calendar. If so, the SQL statements below will identify any scheduled activities that are no longer associated with a Recurring Activity and remove them from the database via SQL. ===== Risk of Data Corruption if Run Improperly ===== **High**. Data is modified and removed in this query. Do not run this except under the direction of a Cyrious Technical Support staff member. Doing otherwise may result in lost or contaminated data. All data modifications done through direct SQL **are permanent and non-reversable**. ===== ===== ===== SELECT SQL ===== Query to select a list of all scheduled activities and macro activity template. This query allows you to review the data prior to running the delete query. [[code_formatsql]] SELECT J.ID as JournalID , J.ClassTypeID -- 21200 macro activity ; 20610 = macro activity template , J.EmployeeID , J.JournalActivityType -- 16 = Macro Activity ; 42 = Macro Activity Template , J.JournalActivityText , J.Description , J.RecurringActivityID , J.RecurringClassTypeID FROM Journal J WITH(NOLOCK) WHERE J.ClassTypeID IN (21200,21250) AND CompletedDateTime IS NULL ; [[code]] ===== DELETE SQL ===== Query to delete all Scheduled Activities and Macro Activity Templates that are no longer associated with a valid Recurring Activity. [[code_formatsql]] -- DELETE FROM Journal -- Remove the -- at the beginning of this statement before executing. WHERE ClassTypeID IN (21200,21250) AND RecurringActivityID NOT IN (SELECT ID FROM RecurringActivity) AND CompletedDateTime IS NULL ; -- delete from RuleActivity -- Remove the -- at the beginning of this statement before executing. where ID not in (Select ID from Journal) [[code]] ===== Version Information ===== * Entered : 1/7/2011 ===== Related SQLs ===== * Backlinks [[include_pagepage_componentbacklinks]]