1. Basic Building Block
A SQL report consists of an SQL code with the following content: SELECT
samples.name AS 'Sample',
samples.description AS 'Description'
FROM samples
WHERE samples.visible_to != 'deleted'
ORDER BY samples.name DESC;
2. Elements
The following elements are commonly used:SELECT
: ColumnsAS
: Column-Description (optional)FROM
: Data source tableWHERE
: ConditionsORDER BY
: Sorting
3. Query Building Blocks
You can use the following query building blocks in your SQL reports:WHERE samples.visible_to != 'deleted'
Excludes deleted samples.WHERE samples.date BETWEEN FROMDATE AND TILLDATE
Allows the entire evaluation to be filtered by date ranges (laboratory database internal variable, see instructions on Variablen in Auswertungen). The filter is displayed above the SQL Report.ORDER BY samples.date DESC
Sorts in descending (DESC) order by sample date (or ASC for ascending).
For more examples of evaluations, refer to: Evaluations -> Examples
4. JOIN
To join multiple tables together, you need a JOIN.
code>SELECT FROM oldTabs
…
JOIN newTabs ON ordTabs.id = newTabs.ordTab_id;
Note: In the LAB DATABASE, all table names are in plural (Tables), while column names are mostly in singular (Table). This makes it easier to distinguish between table names and column names.
Here is a small overview of which tables are linked for the areas: Order-Sample-Result-Parameter-Specification.
5. Link
To obtain links in the result table, use the laboratory database's internal linking system. For example, to link to the sample details view, use:CONCAT('link==../samples/view/', samples.id, '==', samples.name) as 'Samples'
../samples/view/'
= LDB-internal Linksamples.id
=Part of the linksamples.name
= Display value'Proben'
=Column header
6. Linked Master Data Fields
For example, if a master data field in samples (DDF_CUSTOMER) is linked to customer numbers, use the following SELECT/JOIN:customers.name as 'customer'
FROM samples
JOIN customers ON samples.DDF_KUNDE = customers.id
7. Functions
Example | Result | Remark | |
---|---|---|---|
IF-Then(CASE) | SELECT CASE WHEN MyField = 0 | IF MyField = 0 then result = 'Is Null' else result = 'Not 0' | ELSE ist optional |
IF-Then (IF) | IF (MyField = 0,'is 0', 'not 0') | IF MyField = 0 then Result = 'is 0' else Result = 'not 0' | |
Decimal Number format | CAST(REPLACE(parameters.value0, ',', '.') AS DECIMAL(12,2)) | 1.05 -> 1,05 100.2312 -> 100,23 | replaces the comma with a dot and creates with CAST … as DECIMAL(12,2) a decimal number. 12 = Total number of digits, 2 = Number of digits after decimal point |
Last change: 03.04.2024
Allgemeines
Einführungsphase
Mitarbeiter
Aufträge
Proben
Probenvorlage
Berichte
Berichtstabellen Editor
Kunden
Kundenzone (optional)
Anlagen
Angebote
Rechnungen
Parameter
Rechnen mit Parametern
Schnittstellen
Webservice
Transformationscode
Prüfpläne / Grenzwerte / Spezifikationen
Dokumentenlenkung
Prüfmittel
Material
Mitarbeiterschulungen
8D-Report
Sonstiges
PDF-Vorlagen
Fragen und Antworten
Lieferantenbewertung
Dateiverwaltung
Auswertungen
Prozesse