How to delete orphaned call ticket table rows

Version 1

    Details

    What is the SQL query to delete orphaned Call Ticket table rows?  The orphaned call ticket table rows are rows where the CallID does not match a Call Record CallID.


    Resolution

     

    Run the following each individually in SQL Management Studio AFTER backing up the full HEAT database:

    DELETE FROM CallLog WHERE CallID NOT IN (SELECT CallID FROM Subset)

     

    DELETE FROM Subset WHERE CallID NOT IN (SELECT CallID FROM CallLog)

     

    DELETE FROM Asgnmnt WHERE CallID NOT IN (SELECT CallID FROM CallLog)

     

    DELETE FROM Journal WHERE CallID NOT IN (SELECT CallID FROM CallLog)

     

    DELETE FROM Detail WHERE CallID NOT IN (SELECT CallID FROM CallLog)