2026-11-27

Sage 100: Linked Server "SAGE" Returned Message "[ProvideX][ODBC Driver]Expected Lexical Element Not Found: <identifier>"

Getting linked server "SAGE" returned message "[ProvideX][ODBC Driver]Expected lexical element not found: <identifier>"? The ProvideX driver rejects T-SQL join syntax — here is the {oj} syntax it accepts instead.

Full error text:

linked server "SAGE" returned message "[ProvideX][ODBC Driver]Expected lexical element not found: <identifier>".

You see it in SQL Server Management Studio when a query sent through a linked server to Sage 100 Standard or Advanced data fails. The linked server itself is usually fine — a simple single-table query through the same linked server works. What fails is the query text: the ProvideX ODBC driver behind the SOTAMAS90 DSN does not speak T-SQL, and the moment your query uses join syntax (or another construct) written for SQL Server, its parser stops and reports that it expected an identifier where your syntax put something else.

The fix

Rewrite the part of the query that travels to Sage — the string inside OPENQUERY — in ProvideX syntax, and leave everything T-SQL-specific on the SQL Server side.

  1. Inner joins: drop the JOIN keyword. List each table with an alias in the FROM clause, separated by commas, and put the matching conditions in the WHERE clause:

    SELECT *
    FROM SO_SalesOrderHeader SOH, SO_SalesOrderDetail SOD
    WHERE SOH.SalesOrderNo = SOD.SalesOrderNo
    
  2. Outer joins: use the {oj ... } escape, one join per block. An outer join must be wrapped in the ODBC escape sequence, with the join condition in parentheses after ON:

    SELECT *
    FROM {oj CI_Item CII Left Outer Join SO_SalesOrderDetail SOD
          On (CII.ItemCode = SOD.ItemCode) }
    
  3. Three or more tables: only the outer-join pair goes in the block. Put the one pair of tables that needs an outer join inside {oj ... }, list the remaining tables with commas in the FROM clause, and join them in the WHERE clause:

    SELECT *
    FROM SO_SalesOrderHeader SOH,
         {oj SO_SalesOrderDetail SOD Left Outer Join PO_PurchaseOrderHeader POH
             ON (SOD.PurchaseOrderNo = POH.PurchaseOrderNo) }
    WHERE SOH.SalesOrderNo = SOD.SalesOrderNo
    
  4. Keep unsupported constructs out of the OPENQUERY string. Constructs outside the driver's grammar — for example nested sub-SELECTs or T-SQL functions such as DATEPART placed inside the OPENQUERY string — are outside the join grammar the thread documents and are a common cause of this class of parse failure (the thread itself establishes the error for join syntax specifically). Pull the raw rows with a simple query, then aggregate, group, and apply functions in SQL Server (or in your reporting tool) against the returned set.

  5. Test in layers. First run each table alone through the linked server (SELECT * FROM OPENQUERY(SAGE, 'SELECT * FROM CI_Item') style). Then add one join at a time in the syntax above. The first join form that errors is the one to rewrite — the driver gives you no line numbers, so layering is how you find it.

Causes / why this happens

The ProvideX ODBC driver implements its own SQL dialect — a variant of SQL-92 documented in the ProvideX ODBC Driver manual (v4.10) — not Transact-SQL. Its join grammar is the { oj ... } escape: inside the braces you name the first table, the join type (INNER JOIN, with INNER optional, or LEFT OUTER JOIN), the second table, and the ON condition. Anything outside that grammar — a bare T-SQL JOIN chain, multiple joins inside one escape block, subqueries, SQL Server functions — is a token the parser cannot place, and "Expected lexical element not found: <identifier>" is its generic way of saying so. SQL Server then wraps the driver message in the "linked server returned message" shell you actually see.

Per-context variants

If even a single-table query fails, your problem is not this error's usual cause — check the linked server configuration itself (DSN name, provider string, 32-bit vs 64-bit driver/SSMS mismatch) before touching query syntax.

If the query must stay complex, use the architecture experienced Sage 100 consultants fall back on: one unfiltered pass-through view or query per Sage table, with all joining done in SQL Server against those views — or scheduled refresh queries that copy the Sage tables into mirror tables in SQL Server, and report against the mirrors. That pattern also removes the performance cost of joining live ProvideX files on every report run.

Crystal Reports and Access users hit the same parser limit without a linked server. The same rules apply: one {oj} block per outer join, common tables aliased once per join and tied together in the WHERE clause, or one SQL Specific Pass Through Query per table with the joins done in Access.

What doesn't work

  • Standard T-SQL JOIN syntax through OPENQUERY — this is the direct cause of the error, no matter how correct the query is in SQL Server.
  • Several joins inside a single {oj ... } block — the escape holds exactly one join.
  • Filtering on the outer-joined table in the WHERE clause — it silently turns your outer join back into an inner join, dropping the unmatched rows you wanted to keep.
  • Subqueries, DATEPART and similar T-SQL functions inside the driver query — outside the driver's documented grammar; do that work after the data reaches SQL Server rather than inside the OPENQUERY string.

Affected versions

Sage 100 Standard and Advanced (ProvideX database) accessed through the ProvideX ODBC driver 4.x / SOTAMAS90 DSN, including through a SQL Server linked server. Sage 100 Premium stores its data in SQL Server directly, so its tables can be queried in ordinary T-SQL and this error does not apply.

Prevention / best practice

Build a small library of tested ProvideX-syntax queries for your recurring extracts instead of translating T-SQL on the fly — the translation is where this error is born. For anything queried daily, prefer the mirror-table pattern: refresh SQL Server copies of the Sage tables on a schedule with simple single-table queries, and let every report join freely in T-SQL against the mirrors.

Related help

Still stuck? Send us a screenshot of the error, we will diagnose it for free.

Digit Masters has supported Sage 100 and Sage 300 since 1997. Send the screenshot through our contact page or to contact@digitmasters.com, or call (800) 965-4262.

Ready to Optimize Your Sage ERP?

Speak with a CPA-led Sage consultant. Free initial consultation — English or Chinese.

Get a Free Consultation