Exporting a Table to CSV Format

The template library script Generic Table Exporter allows exporting the contents of a table to a CSV file.

The configuration of the script requires the following components :

  • Table

  • FieldDelimiter: character used to delimit values of a row.

  • CSVPath: the path to the CSV file, on disk, on which the alarms history will be exported.

  • Query, una SQL query tramite la quale è possibile filtrare i dati.

SQL Query Configuration

È possibile filtrare una tabella tramite una Query SQL.

A query can be written as text, or using a String formatter and its relative placeholders sql_identifier and sql_literal`.

The following examples show some use cases.

Note

The name of the table should not be specified in the FROM clause but rather in the dynamic link to the BrowseName of the table with an {0:sql_identifier} placeholder in a string formatter.

Filtering by Time

The archived data can be filtered by time using the Time column (or Timestamp) containing the date and time.

The literal to be used in the placeholder of the string formatter is sql_literal. It is recommended to use a temporary DateTime variable for this purpose.

Examples of filtering by time:

-- Esporta i record che riportano un Timestamp superiore ad un determinato istante di tempo
SELECT * FROM {0:sql_identifier} WHERE Timestamp > {1:sql_literal}

-- Esporta i record che riportano un Timestamp compreso tra due istanti di tempo
SELECT * FROM {0:sql_identifier} WHERE Timestamp BETWEEN {1:sql_literal} AND {2:sql_literal}

Note

Nel caso si voglia effettuare su di un Logger un filtro temporale, questo deve essere eseguito sulla colonna Timestamp. Invece, nel caso in cui si voglia filtrare lo storico allarmi la colonna di riferimento è Time.

Filtering Alarms by Severity

The Severity column contains the value of the severity of an alarm. Using a filter on this column allows filtering the various severities of an alarm grid or alarm history grid.

-- Esporta lo storico degli allarmi con gravità 1.
SELECT * FROM {0:sql_identifier} WHERE Severity = 1

-- Esporta lo storico degli allarmi con gravità compresa tra 1 e 3.
SELECT * FROM {0:sql_identifier} WHERE Severity BETWEEN 1 AND 3

Filtering by Alarm or Variable

The ConditionName column contains the name of the alarm so archived alarms can be filtered to obtain specific alarms or alarm names can be filtered if they follow a specific pattern.

The condition can be used on the SourceName column in case we want to filter by the input variable.

-- Esporta lo storico degli allarmi con un determinato BrowseName passato
-- tramite formattatore al segnaposto 1
SELECT * FROM {0:sql_identifier} WHERE ConditionName = {1:sql_literal}

-- Esporta lo storico degli allarmi collegati alla variabile
SELECT * FROM {0:sql_identifier} WHERE SourceName = {1:sql_literal}

-- Esporta lo storico degli allarmi che iniziano per Exclusive
SELECT * FROM {0:sql_identifier} WHERE ConditionName LIKE 'Exclusive%'

Filtering Recorded Alarms

Some columns of the logger can be exported explicitly through the SELECT statement.

-- Esporta lo storico degli allarmi con le sole colonne italiane
SELECT "ActiveState_it-IT", "AckedState_it-IT", "ConfirmedState_it-IT", "ConditionName", "EnabledState_it-IT", "SourceName", "Time", "Message_it-IT", "Severity" FROM {0:sql_identifier}