> For the complete documentation index, see [llms.txt](https://docs.videc.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.videc.de/june5-3.7/en/datenquellenunterstuetzung-und-einbindung/microsoft-ole-db/sql-befehle.md).

# SQL Commands

Basically, two command groups are distinguished. The commands for determining the measurement variables and the commands for displaying the archived data.

## Determining Measurement Variables

The command for determining measurement variables is a SQL SELECT statement that is structured according to the following syntax:

```
SELECT [MyID] AS TagID, [MyName] AS TagName, [MyUnit] AS TagUnit FROM [MyTags]
```

The command for determining measurement variables contains four placeholders.

* \[MyID] specifies which column contains the ID of the measurement variable.
* \[MyName] specifies which column contains the name of the measurement variable.
* \[MyUnit] specifies which column the unit for each measurement variable is determined from.
* \[MyTags] specifies which table the measurement variables are determined from.

For the table shown in the section [SQL Table Measurement Variables](/june5-3.7/en/datenquellenunterstuetzung-und-einbindung/microsoft-ole-db/sql-tabelle-messgroessen.md), some properties of the measurement variables can be determined with the following SQL commands:

```
SELECT [TagID] AS TagID, [TagShortName] AS TagShortName, [TagName] AS TagName, [TagDescription] AS TagDescription, [TagUnit] AS TagUnit FROM [Variable]
SELECT [TagID] AS TagID, [TagName] AS TagName, [TagUnit] AS TagUnit FROM [Variable]
SELECT [TagID] AS TagID, [TagID] AS TagName, [TagUnit] AS TagUnit FROM [Variable]
```

{% hint style="info" %}

* The placeholders for determining the unique identification, name and unit must be parameterized.
* If the placeholder for determining the short name is not explicitly included in the command, the short name is determined using the placeholder for determining the unique identification.
  {% endhint %}

## Determining Measurement Values

The commands for determining measurement values are SQL SELECT statements that are structured according to the following syntax.

{% code overflow="wrap" %}

```sql
SELECT [MyValue] AS Value, [MyTimestamp] AS Timestamp FROM [MyData] WHERE [MyId] =<<TagID>> AND [MyTimeStamp]>  <<TS_From>> AND [MyTimeStamp]<= <<TS_To>>
```

{% endcode %}

In this SQL statement there are both keywords and placeholders. The keywords are enclosed in double angle brackets. Before a command is executed, the keywords are automatically replaced.

* \[MyValue] specifies which column data is read from.
* \[MyTimestamp] specifies which column the data timestamps are read from.
* \[MyData] specifies which table the data is read from.
* \[MyID] specifies the ID of the measurement variables whose data is to be imported.

For the table shown in the section [SQL Table Measurement Values](/june5-3.7/en/datenquellenunterstuetzung-und-einbindung/microsoft-ole-db/sql-tabelle-messwerte.md), the data can be determined with the following SQL commands.

```
SELECT [RawValue] AS Value, [RawDateTime] AS Timestamp FROM [RawData] WHERE [TagID] =<<TagID>> AND [RawDateTime]>=  <<TS_From>> AND [RawDateTime]< <<TS_To>>
```

If the table also provides compressed data, a filter must be added to the SQL command to specify the compression interval. The compression interval must match the predefined compression intervals defined in JUNE5. The following table shows the compression intervals of JUNE5 for the OLE DB data source.

| Compression Interval | Description (Interval) |
| -------------------- | ---------------------- |
| PROCESS              | Raw value              |
| INTERVAL1            | 1 Minute               |
| INTERVAL2            | 5 Minutes              |
| INTERVAL3            | 15 Minutes             |
| INTERVAL4            | 30 Minutes             |
| INTERVAL5            | 1 Hour                 |
| INTERVAL6            | 2 Hours                |
| DAY1                 | Day                    |
| WEEK                 | Week                   |
| MONTH                | Month                  |
| YEAR                 | Year                   |

A SQL statement for querying hourly values can be structured like one of the following statements:

```
SELECT [MyValue] AS Value, [MyDateTime] AS Timestamp FROM [MyHourData] WHERE [MyID] =<<TagID>> AND [MyDateTime]>  <<TS_From>> AND [MyDateTime]<= <<TS_To>>
```

## Determining Events

The command for determining events is a SQL SELECT statement. For the table shown in the section [SQL Table Events](/june5-3.7/en/datenquellenunterstuetzung-und-einbindung/microsoft-ole-db/sql-tabelle-ereignisse.md), the events can be determined with the following SQL command.

```
SELECT [Von], [Bis], [Quittiert], [Namensraum], [ID], [Name], [Beschreibung], [Priorität], [Bedingung], [Status], [Wert], [Kategorie], [Benutzer], FROM [Energy].[dbo].[Events]
```

*This SQL command must not contain an ORDER BY clause!*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.videc.de/june5-3.7/en/datenquellenunterstuetzung-und-einbindung/microsoft-ole-db/sql-befehle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
