# Infor LN SQL Query Generator for Oracle and SQL Server

> Source: https://netray.co/tools/infor-ln-sql-query-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in the table, company number and key range to get read-only SQL for the LN database, with the physical table name built for you.

## Category

infor-ln

## Erp

Infor LN

## Audience

- LN developer
- LN administrator
- Reporting analyst

## Tool

**Kind:** template

**Output:** code

**Language:** sql

**Fields:**

#### Database schema or owner

**Key:** schema

**Type:** text

**Default:** baandb

**Help:** The schema that owns the LN tables in your database. Check with your DBA.

#### Header table (package, module, number)

**Key:** header_table

**Type:** text

**Default:** tdsls400

**Help:** Logical table name without the leading t and without the company number.

#### Line table (package, module, number)

**Key:** line_table

**Type:** text

**Default:** tdsls401

#### Company number

**Key:** company

**Type:** text

**Default:** 100

**Help:** Three digit LN company number appended to the physical table name.

#### Key column

**Key:** key_col

**Type:** text

**Default:** t_orno

**Help:** Column used to join header to lines and to filter.

#### Key from

**Key:** key_from

**Type:** text

**Default:** 100000

#### Key to

**Key:** key_to

**Type:** text

**Default:** 100999

**Blocks:**

#### Filtered select on the header table

**Body:** SELECT *
FROM {{schema}}.t{{header_table}}{{company}}
WHERE {{key_col}} BETWEEN {{key_from}} AND {{key_to}}
ORDER BY {{key_col}};

#### Header joined to lines

**Body:** SELECT h.{{key_col}}, l.*
FROM {{schema}}.t{{header_table}}{{company}} h
JOIN {{schema}}.t{{line_table}}{{company}} l
  ON l.{{key_col}} = h.{{key_col}}
WHERE h.{{key_col}} BETWEEN {{key_from}} AND {{key_to}}
ORDER BY h.{{key_col}};

#### Row counts for reconciliation

**Body:** SELECT COUNT(*) AS header_rows
FROM {{schema}}.t{{header_table}}{{company}};

SELECT COUNT(*) AS line_rows
FROM {{schema}}.t{{line_table}}{{company}};

#### Lines without a header (orphan check)

**Body:** SELECT l.{{key_col}}
FROM {{schema}}.t{{line_table}}{{company}} l
LEFT JOIN {{schema}}.t{{header_table}}{{company}} h
  ON h.{{key_col}} = l.{{key_col}}
WHERE h.{{key_col}} IS NULL;

**Notes:** Use read-only database accounts and run heavy queries on a replica or off hours. Column names beginning t_ and the table naming pattern t + package + module + number + company are standard in LN, but confirm column names for your table in the data dictionary. Item codes are often stored with leading blanks, so use TRIM when comparing. Never write to LN tables with SQL: use sessions, DAL or the supported APIs.

## Content

**Intro:** Infor LN and Baan keep each company's data in physical tables named from the package, module, table number and company. This generator builds that name for you and gives you safe, read-only SQL for the common checks.

**Sections:**

#### How to use the generator

**Body:** Enter the schema that owns the LN tables, the logical table names for header and lines, your company number and the key range you care about. The four blocks update live: a filtered select, a header to line join, row counts and an orphan check. Copy the block you need into your SQL client, or export the whole set. Always start with a narrow key range, because LN tables can hold millions of rows and an unfiltered join will punish a shared database.

#### How LN physical table names work

**Body:** A logical table such as tdsls400 belongs to package td, module sls, table number 400. In the database it becomes t, then the logical name, then the three digit company number, for example ttdsls400100. Columns follow the pattern t_ plus the field name, such as t_orno for the order number. Because the company number is part of the table name, the same query pattern runs against any company by changing one field.

**Bullets:**

- Logical name: package (2 letters), module (3 letters), table number (3 digits)
- Physical name: t + logical name + company number
- Column name: t_ + field name
- Check the data dictionary for exact columns before relying on them

#### Reading the results

**Body:** Header and line counts should be in a sensible ratio for your business, and the orphan check should return no rows. Orphans usually point to a failed conversion load or a partially deleted record. Compare counts before and after a migration load, and keep the numbers in your cutover log. If a join returns far more rows than expected, a key is probably not unique on its own and needs a second column, for example a position number.

#### Common mistakes

**Body:** The most common errors are querying the wrong company number, forgetting that item codes carry leading blanks, and running reports against the production database in office hours. A second trap is trusting SQL to show business meaning: enumerated fields are stored as numbers, and the text lives in the domain definition. Use SQL for data checks and reconciliation, and use LN sessions or DAL for anything that changes data.

**Cta:** If your team writes the same LN queries every week, we can put a governed question layer over the data so people ask in plain language and see the SQL it ran.

**Faq:**

#### Can I use these queries on both Oracle and SQL Server?

**Answer:** The statements use standard SQL: SELECT, JOIN, BETWEEN and COUNT. They run on both databases once you set the right schema or owner. If your LN installation uses a different database, check identifier quoting and schema rules with your DBA before running them.

#### Is it safe to write to LN tables with SQL?

**Answer:** No. Direct updates bypass DAL checks, audit trails and referential logic, and can corrupt data in ways that sessions cannot repair. Use read-only SQL for analysis and use sessions, exchange schemes or supported APIs for any change.

#### Why does my item filter return nothing?

**Answer:** Item codes in LN are often stored with leading blanks to fill the segment width. A plain equality test on the visible code misses them. Apply TRIM to the column or match with the padded value, and verify with a known item first.

#### How do I find the right table name?

**Answer:** Open the session in LN, use the about or table information option to see the tables it uses, or search the data dictionary by field name. Then plug the logical name into this generator.

## Search terms

infor ln sql query, baan sql query table, infor ln database tables, ln physical table name, baan t_orno query, infor ln oracle query, infor ln sql server query, infor ln read only reporting

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
