{}

Our Brands

Impact-Company-Logo-English Black-01-177x54

Welcome to the Schneider Electric Website

Welcome to our website.
Search FAQs
PME 7.2/8.x/9.0/2020: How to execute the TrimRecords stored procedure via a scheduled task in SQL Server Agent

Issue
To manage drive space limitations, it is desirable to only keep a specified amount of historical data available for reporting.  For some customers this may be 1, 2, 3...10 years. However, it is not desirable to create archive databases that have to then be deleted themselves.

Product Line
Power Monitoring Expert 7.x
Power Monitoring Expert 8.x
Power Monitoring Expert 9.0
Power Monitoring Expert 2020

Environment
SQL Server Management Studio

Cause
An archive database takes up additional space on the hard drive, therefore it is desirable to only remove old data on a periodic basis.

Resolution
*Warning: Irreparable database damage can occur. This procedure should only be performed by users familiar with SQL Server Management Studio. Databases should be backed up prior to performing this procedure.*


1. Expand SQL Server Agent
2. Right-click Jobs > New Job...

SQL Server Management Studio

3. Name = ION_Data Trim Schedule
4. Click Steps > New
5. Step name = Trim Data

NOTE: If this system needs to retain 2 years in the live database, the 'DATEADD' function within the 'myEndDate' variable needs to be modified to the following:
DATEADD(YEAR, -2, GETDATE())
If this system needs to retain 6 months in the live database, it should be changed to:
DATEADD(MONTH, -6, GETDATE())
Define a 'StartDate' as per the specified date format (yyyy-mm-dd). Example: '1900-01-1'.

The query below trims the DataLog2, WaveformLog2, and EventLog2 tables. Change the @TrimDataLog, @TrimWaveForm, and @TrimEvent parameters to 0 (NO) or 1 (YES) as required.

6. In the Command pane type the following based on the version of PME being used in the system:

For PME 7.2 and 8.x systems:

USE [ION_Data]
GO

DECLARE    @return_value int
DECLARE    @MyEndDate datetime2
select           @MyEndDate = convert(varchar(10), DATEADD(MONTH, -1, cast(getdate() as date)), 20)

EXEC    @return_value = [dbo].[TrimRecords]
@StartDate = 'yyyy-mm-dd',
@EndDate = @MyEndDate,
@TrimDataLog = 1,
@TrimWaveForm = 1,
@TrimEvent = 1

For PME 9.0 and 2020 systems:

DECLARE @StartDate datetime = N'2000-01-01'
DECLARE @EndDate datetime = DATEADD(MONTH, -1, GETDATE())

EXEC [ION_Data].[dbo].[TrimRecords]
@StartDate
, @EndDate
, @TrimDataLog = 1
, @TrimWaveForm = 1
, @TrimEvent = 1

7. Click Schedules > New
8. Name = Trim Data
9. Set the frequency that meets this systems needs.  To just keep a rolling X (where X is the number chosen by the customer) amount of years in the database this could be set to monthly.  If it is desirable to keep a full previous X years this will need to be run yearly on January 1st.
10. Click OK, then Click OK on the Job window.

Schneider Electric Canada

Explore more
Range:
Articles that might be helpful Users group

Discuss this topic with experts

Visit our Community for first-hand insights from experts and peers on this topic and more.
Explore more
Range: