> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/codesys-hvac/mysql-library/beispiele/werte-und-sonderzeichen.md). Agents can also search and read this documentation through its [MCP server](https://support.powerio.com/hub/~gitbook/mcp).

# Werte und Sonderzeichen

## Werte und Sonderzeichen

In CODESYS müssen Sonderzeichen in Strings mit `$` kodiert werden.

#### Wichtigste $ Codes

| Zeichen                 | Code  | Verwendung      | Beispiel               |
| ----------------------- | ----- | --------------- | ---------------------- |
| `'` (Apostroph)         | `$27` | Text in SQL     | `$27Max Mustermann$27` |
| `"` (Anführungszeichen) | `$22` | Selten benötigt | `$22Text$22`           |
| `$` (Dollar)            | `$$`  | Dollar-Zeichen  | `$$100`                |

### Praktische Beispiele

#### Text-Werte in SQL einfügen

```iecst
// Falsch - funktioniert nicht:
MySQL_Command[0] := 'INSERT INTO users (name) VALUES ('Max')';

// Richtig - mit $27:
MySQL_Command[0] := 'INSERT INTO users (name) VALUES ($27Max$27)';
```

#### Dynamische Text-Werte

```iecst
VAR
    sName : STRING := 'Max Mustermann';
    sCity : STRING := 'Berlin';
END_VAR

// Text mit $27 einschließen
MySQL_Command[0] := 'INSERT INTO users (name, city) VALUES ($27';
MySQL_Command[1] := CONCAT(sName, '$27, $27');
MySQL_Command[2] := CONCAT(sCity, '$27)');

// Ergebnis: INSERT INTO users (name, city) VALUES ('Max Mustermann', 'Berlin')
```

#### WHERE-Bedingung mit Text

```iecst
VAR
    sSearchName : STRING := 'Schmidt';
END_VAR

MySQL_Command[0] := 'SELECT * FROM users WHERE name = $27';
MySQL_Command[1] := CONCAT(sSearchName, '$27');

// Ergebnis: SELECT * FROM users WHERE name = 'Schmidt'
```

#### Datum und Zeit

```iecst
// Datum
MySQL_Command[0] := 'SELECT * FROM logs WHERE date = $272024-01-15$27';

// Datum und Zeit
MySQL_Command[0] := 'SELECT * FROM logs WHERE timestamp = $272024-01-15 10:30:00$27';
```

#### Zahlen brauchen kein $27

```iecst
// Richtig - Zahlen ohne $27:
MySQL_Command[0] := 'INSERT INTO data (value) VALUES (123)';

// Falsch - nicht bei Zahlen:
MySQL_Command[0] := 'INSERT INTO data (value) VALUES ($27123$27)';  // FALSCH!
```

#### NULL-Werte

```iecst
// Richtig - NULL ohne $27:
MySQL_Command[0] := 'INSERT INTO data (value) VALUES (NULL)';

// Falsch:
MySQL_Command[0] := 'INSERT INTO data (value) VALUES ($27NULL$27)';  // FALSCH!
```

### Referenz

#### Datentyp -> SQL Format

| CoDeSys Typ  | SQL Format                  | Beispiel Code               |
| ------------ | --------------------------- | --------------------------- |
| **STRING**   | `$27text$27`                | `$27Berlin$27`              |
| **INT**      | Direkt                      | `123`                       |
| **REAL**     | Direkt (mit Punkt)          | `23.5`                      |
| **BOOL**     | Als 0/1 oder Text           | `1` oder `$27TRUE$27`       |
| **DATE**     | `$27YYYY-MM-DD$27`          | `$272024-01-15$27`          |
| **TIME**     | `$27HH:MM:SS$27`            | `$2710:30:00$27`            |
| **DATETIME** | `$27YYYY-MM-DD HH:MM:SS$27` | `$272024-01-15 10:30:00$27` |

### Häufige Fehler vermeiden

#### Falsch

```iecst
MySQL_Command[0] := 'INSERT INTO users (name) VALUES ('Max')';  
// Syntaxfehler!
```

#### Richtig

```iecst
MySQL_Command[0] := 'INSERT INTO users (name) VALUES ($27Max$27)';
```

#### Falsch

```iecst
MySQL_Command[0] := 'INSERT INTO data (value) VALUES ($27100$27)';  
// Zahl als Text!
```

#### Richtig

```iecst
MySQL_Command[0] := 'INSERT INTO data (value) VALUES (100)';
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.powerio.com/hub/codesys-hvac/mysql-library/beispiele/werte-und-sonderzeichen.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
