> 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).

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

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
