Solutions
...
Litmus Production Record Datab...
Interacting with Litmus Produc...

Reading Production Record Event Data Transposed with UTC timestamp

8min

Use Cases

Returning event data recorded by Litmus Production Record Database through the use of these SELECT statements can be used for example by any visualization platform which allows to integrate with MSSQL like;

  • Grafana
  • PowerBI
  • Tableau

Further can these queries be used by any other application which allows for an ODBC connection such as:

  • Excel
  • C#
  • .Net
  • Python
  • R

They can also be part of a larger stored procedure developed by users with T-SQL.

By default, Litmus Production Record stores Event items as rows and not individual columns.

There can be cases where users may want to transpose the default result table to turn Event Items into columns.

For this, Litmus Production Record Database provides a prepared way.

Method

As Litmus Production Record makes use of the EAV (Entity-Attribute-Value) model for databases, to allow for full flexibility for defining a data model, each data model item returned by the function described in the chapter

is an individual row in the result table.

To show the data in a table where each data model item is a column, the original result table needs to be pivoted.

To allow users to accomplish this task out of the box, Litmus Production Record Database offers the stored procedure PROREC_ProRec_GetTransposedProRecDataUTC.

The stored procedure will create a temporary table which holds the data, against which the user can then run a classic select statement, to allow users to ready the columns they are interested in.

By default the temporary table is called ##TransposeProRecData but can be changed to a custom table name, which is important if for example a dashboard has several panels which are getting data through the stored procedure ROREC_ProRec_GetTransposedProRecDataUTC.

Input Variables

Variable name

Datatype

Description

Example

@Resulttable

VARCHAR (50)

The stored procedure will store the returned data in a temporary table to allow the user to make use of a SELECT query to only return the columns they are interested in as well as the use of WHERE, ORDER and Group by clauses.

This is the temporary table the user queries against after running the stored procedure.

It is recommended to always provide a name for the temporary table, so that your query is not impacted by another user.

Temporary tables in Microsoft SQL are always prefixed with two '#' (Example: ##TransposeProRecData).

Therefore if a user does not add two '#', the stored procedure will add the prefix to the name. This means that in the select query, the user will have to use the custom name with the two '#' prefix.

It is possible to not provide a name for the temporary table and use the DEFAULT value of ##TransposeProRecData

















##reasoncodelevel2





















DEFAULT

@ProRecID

BIGINT

A specific internal Production Record ID. If no specific Production Record ID is to be queried or to get a list of Production Record ID's, the value can also be DEFAULT which will assume the value null.

26817







DEFAULT

@Identifiers

VARCHAR (8000)

A key-value pair or comma separated list of key-value pairs for know Identifiers which describe a Production Record.



If no specific Identifiers are to be queried or to get a list of Identifiers 's, the value can also be DEFAULT which will assume the value %.

Asset:L2_Machine1_1_MB,START_TIME:1678295211950









DEFAULT

@NodeName

VARCHAR (50)

The Data Model root Node name. If no specific NodeName is to be queried or to get a list of NodeName's, the value can also be DEFAULT which will assume the value %.

TestNode







DEFAULT

@Level1

VARCHAR (50)

The name of a the first Sub Level in the Data Model (if defined).



If no specific Level1 is to be queried or to get a list of Level1's, the value can also be DEFAULT which will assume the value %.

TestLevel1









DEFAULT

@Level2

VARCHAR (50)

The name of the second Sub Level in the Data Model (if defined).



If no specific Level2 is to be queried or to get a list of Level2's, the value can also be DEFAULT which will assume the value %.

TestLevel2









DEFAULT

@Level3

VARCHAR (50)

The name of the third Sub Level in the Data Model (if defined).



If no specific Level3 is to be queried or to get a list of Level3's, the value can also be DEFAULT which will assume the value %.

TestLevel3









DEFAULT

@Level4

VARCHAR (50)

The name of the fourth Sub Level in the Data Model (if defined).



If no specific Level4 is to be queried or to get a list of Level4's, the value can also be DEFAULT which will assume the value %.

TestLevel4









DEFAULT

@Level5

VARCHAR (50)

The name of the fifth Sub Level in the Data Model (if defined).



If no specific Level5 is to be queried or to get a list of Level5's, the value can also be DEFAULT which will assume the value %.

TestLevel5









DEFAULT

@ItemName

VARCHAR (50)

The name of the Item in the Data Model.



If no specific Item is to be queried or to get a list of Item's, the value can also be DEFAULT which will assume the value %.

ItemName







DEFAULT

@ItemValue

VARCHAR (256)

A specific value for the Item in the Data Model.



If no specific Value for the Item is to be queried or to return all Values, the value can also be DEFAULT which will assume the value %.

20







DEFAULT

@Eng_Unit

VARCHAR (20)

A specific engineering Unit for the Item in the Data Model (if defined).



If no specific Engineering Unit for the Item is to be queried or to return all engineering units if defined, the value can also be DEFAULT which will assume the value %.

Kg









DEFAULT

@Occurance

INTEGER

A specific occurrence of the Item in the Data Model.



If no specific occurrence for the Item is to be queried or to return all occurrence's, the value can also be DEFAULT which will assume the value null.



This can be useful if for example an operation can run multiple times throughout a process.

2







DEFAULT

@StartTime

DATETIME

The start of the time period for which to query data.



If no specific start time is required, the value can also be DEFAULT which will assume the value null. This will trigger the function to calculate a start time of -1h from the current time stamp.



This means the default time period for which data are returned is always the last hour.

2023-03-09T13:04:39.647







DEFAULT

@EndTime

DATETIME

The end of the time period for which to query data.



If no specific end time is required, the value can also be DEFAULT which will assume the value null. This will trigger the function to use the current time stamp.



This means the default time period for which data are returned is always the last hour.

2023-03-10T13:04:39.647







DEFAULT

@StartTimeItem

VARCHAR (50)

The Function will try to calculate the overall Duration of each recorded events and sub step included in the event. To do so, it requires to know what is the Item which does symbolize the start of the event. If users have followed the Litmus recommendations and used "START_TIME", the value can be set as DEFAULT. Otherwise, the user needs to provide the respective Item. If the Item does not exist or was not recorded, the Duration will not calculated and returned.

StartTime























DEFAULT

@EndTimeItem

VARCHAR (50)

The Function will try to calculate the overall Duration of each recorded events and sub step included in the event. To do so, it requires to know what is the Item which does symbolize the end of the event or sub step. If users have followed the Litmus recommendations and used "END_TIME", the value can be set as DEFAULT. Otherwise, the user needs to provide the respective Item. If the Item does not exist or was not recorded, the Duration will not calculated and returned.

EndTime























DEFAULT

@FilterItemName1

VARCHAR (256)

In cases where results are to be filtered additionally to the Identifiers, for example based on the value of a specific item, the function allows to provide up to 5 additional filters for this purpose.

This can be understood similar to the use of where clauses, but reduces the complexity for users.

To use the filter, the user has to provide the hierarchy and item name as a comma-separated string followed by the item value separated by a double point.

If no specific Filter is to be used the value can also be DEFAULT which will assume the value % which applies no filter.

'Production,Asset,Step1,Site:LA'























DEFAULT

@FilterItemName2

VARCHAR (256)

In cases where results are to be filtered additionally to the Identifiers, for example based on the value of a specific item, the function allows to provide up to 5 additional filters for this purpose.

This can be understood similar to the use of where clauses, but reduces the complexity for users.

To use the filter, the user has to provide the hierarchy and item name as a comma-separated string followed by the item value separated by a double point.

If no specific Filter is to be used the value can also be DEFAULT which will assume the value % which applies no filter.

'Production,Asset,Step1,Plant:Plant1'























DEFAULT

@FilterItemName3

VARCHAR (256)

In cases where results are to be filtered additionally to the Identifiers, for example based on the value of a specific item, the function allows to provide up to 5 additional filters for this purpose.

This can be understood similar to the use of where clauses, but reduces the complexity for users.

To use the filter, the user has to provide the hierarchy and item name as a comma-separated string followed by the item value separated by a double point.

If no specific Filter is to be used the value can also be DEFAULT which will assume the value % which applies no filter.

'Production,Asset,Step1,Shift:2'























DEFAULT

@FilterItemName4

VARCHAR (256)

In cases where results are to be filtered additionally to the Identifiers, for example based on the value of a specific item, the function allows to provide up to 5 additional filters for this purpose.

This can be understood similar to the use of where clauses, but reduces the complexity for users.

To use the filter, the user has to provide the hierarchy and item name as a comma-separated string followed by the item value separated by a double point.

If no specific Filter is to be used the value can also be DEFAULT which will assume the value % which applies no filter.

'Production,Asset,Step1,Line:1'























DEFAULT

@FilterItemName5

VARCHAR (256)

In cases where results are to be filtered additionally to the Identifiers, for example based on the value of a specific item, the function allows to provide up to 5 additional filters for this purpose.

This can be understood similar to the use of where clauses, but reduces the complexity for users.

To use the filter, the user has to provide the hierarchy and item name as a comma-separated string followed by the item value separated by a double point.

If no specific Filter is to be used the value can also be DEFAULT which will assume the value % which applies no filter.

'Production,Asset,Step1,Asset:Machine1'























DEFAULT

@WithRecordTimes

BIT

Data are stored with the timestamp (RecordTime) when they where recorded in Litmus Production Record Database.

When pivoting the result table, users can decide if they want to organize the pivoted table by this RecordTime (@WithRecordTimes = 1) or by its Occurrence (@WithRecordTimes = 0).

The value can also be DEFAULT which will assume the value 0 which returns the data based on its Occurrence.

0

How to use

To query transposed production record event data, execute the stored procedure PROREC_ProRec_GetTransposedProRecDataUTC first providing all the required inputs first. Followed by a SELECT statement against the table ##OccurrenceTransposeProRecData. Below is an example using T-SQL in SQL Server Management Studio:

exec [LE_ProductionRecord].[dbo].[PROREC_ProRec_GetTransposedProRecDataUTC] @Identifiers = N'START_TIME:1679655872013,Asset:L1_Machine2_1_MB' select * from ##TransposeProRecData;

Result

The function returns a table as result.

Document image


Additional Options

It is possible to reduce the number of columns returned by the SELECT statement. Below is an example using T-SQL in SQL Server Management Studio:

exec [LE_ProductionRecord].[dbo].[PROREC_ProRec_GetTransposedProRecDataUTC] @Identifiers = N'START_TIME:1679655872013,Asset:L1_Machine2_1_MB' select ProRecID, Asset,START_TIME, END_TIME,Duration from ##TransposeProRecData;

This will reduce the number of columns returned to only the three selected.

Document image


It is possible to group the data based on the time they are recorded

exec [LE_ProductionRecord].[dbo].[PROREC_ProRec_GetTransposedProRecDataUTC] @Identifiers = N'START_TIME:1679655872013,Asset:L1_Machine2_1_MB', @WithRecordTimes = 1 select * from ##TransposeProRecData;

The result will be a table, where the data in each column is displayed based on the time they where recorded.

Document image