Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:24:51+00:00 2026-06-17T05:24:51+00:00

I tried to run a dynamically generated SQL query within PHP targeting an Sybase

  • 0

I tried to run a dynamically generated SQL query within PHP targeting an Sybase SQL-Anywhere database and I got the following error:

Warning: sybase_query(): message: SQL Anywhere Error -680: Invalid
expression in WHERE clause of Transact-SQL outer join (severity 16) in
/path/to/file.php

SQL Query String:

SELECT DISTINCT v_InventoryMaster.INV_ScanCode, v_InventoryMaster.INV_ReceiptAlias 
FROM ecrs.v_InventoryMaster
WHERE ( v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 6 
  )
  OR v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 14 
  )
  OR v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 25 
  )
  -- more OR clause subqueries with different ILD_DIS_FK values
)
ORDER BY v_InventoryMaster.INV_ScanCode

I’m not completely new to SQL or interfacing with a database, but this message has me stumped. It claims that there is an invalid expression in the WHERE clause, but I can’t see how the query is illegally structured. My guess is the error involves the OR and joining of the two search results.

Furthermore, by running these three separate queries and combining the results (in Excel), returns the correct set of results:

Query A:

SELECT DISTINCT v_InventoryMaster.INV_ScanCode, v_InventoryMaster.INV_ReceiptAlias 
FROM ecrs.v_InventoryMaster
WHERE ( v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 6 
  )
ORDER BY v_InventoryMaster.INV_ScanCode

Query B

SELECT DISTINCT v_InventoryMaster.INV_ScanCode, v_InventoryMaster.INV_ReceiptAlias 
FROM ecrs.v_InventoryMaster
WHERE ( v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 14 
  )
ORDER BY v_InventoryMaster.INV_ScanCode

Query C

SELECT DISTINCT v_InventoryMaster.INV_ScanCode, v_InventoryMaster.INV_ReceiptAlias 
FROM ecrs.v_InventoryMaster
WHERE ( v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = 25 
  )
ORDER BY v_InventoryMaster.INV_ScanCode

To clarify what return results I want:

enter image description here

Sybase documentation about error -680 says the following:

An expression in the WHERE clause of a query that uses Transact-SQL
syntax contains a comparison of a column from the NULL-supplying table
with a subquery or an expression that references a column from another
table.

  1. What is invalid about the original SQL query?

  2. What does the documented explanation mean?

  3. How could I edit the original SQL query to get the desired results?

Note that since this query was dynamically generated I want to know how I can change the statements between the OR clauses:

Statement Structure:

  v_InventoryMaster.INV_PK NOT IN (
    SELECT DISTINCT v_InventoryMaster.INV_PK 
    FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
    WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
    AND StockInventoryLinkDiscounts.ILD_DIS_FK = value -- value dynamically chosen by user
  )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:24:52+00:00Added an answer on June 17, 2026 at 5:24 am

    You could trivially replace the fragments:

    v_InventoryMaster.INV_PK NOT IN (
        SELECT DISTINCT v_InventoryMaster.INV_PK 
        FROM ecrs.v_InventoryMaster, ecrs.StockInventoryLinkDiscounts
        WHERE v_InventoryMaster.INV_PK = StockInventoryLinkDiscounts.ILD_INV_FK
        AND StockInventoryLinkDiscounts.ILD_DIS_FK = value -- value dynamically chosen by user
      )
    

    By:

     NOT EXISTS (
        SELECT * 
        FROM  ecrs.StockInventoryLinkDiscounts sild
        WHERE sild.ILD_INV_FK = tbl.INV_PK
        AND sild.ILD_DIS_FK = value -- value dynamically chosen by user
        --           ^^^^^ NOTE: this should probably be sild.ILD_DIS_PK
      )
    

    With tbl being the correlation name for the outer query; the outer query would become:

    SELECT DISTINCT v_InventoryMaster.INV_ScanCode
          , v_InventoryMaster.INV_ReceiptAlias 
    FROM ecrs.v_InventoryMaster tbl
    

    Also note that I removed the ecrs.v_InventoryMaster table from the subquery, since it is already present in the outer query, and would result in exactly the same row(s) being checked as the outer query already has found.

    This will give the complete query as:

    SELECT DISTINCT v_InventoryMaster.INV_ScanCode
          , v_InventoryMaster.INV_ReceiptAlias 
    FROM ecrs.v_InventoryMaster tbl
    WHERE NOT EXISTS (
        SELECT * 
        FROM  ecrs.StockInventoryLinkDiscounts sild
        WHERE sild.ILD_INV_FK = tbl.INV_PK
        AND sild.ILD_DIS_FK = 6
      )
    OR NOT EXISTS (
        SELECT * 
        FROM  ecrs.StockInventoryLinkDiscounts sild
        WHERE sild.ILD_INV_FK = tbl.INV_PK
        AND sild.ILD_DIS_FK = 14
      )
    OR NOT EXISTS (
        SELECT * 
        FROM  ecrs.StockInventoryLinkDiscounts sild
        WHERE sild.ILD_INV_FK = tbl.INV_PK
        AND sild.ILD_DIS_FK = 25
      )
    ;
    

    My guess is that the parser is confused by the unaliased references to ecrs.v_InventoryMaster. Another possibility is that the range table is full (if you have a lot of subquery-terms)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just tried to run my test app and I got this error: 2012-06-16
I received the following error when I tried to run a C# WinForms application
I tried to run the following command and it says there is nothing to
I've tried to run the application in two situations: with SQL Server compact edition
I tried to run the directx samples from ..\Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\directx\d3dm\tutorials on a
I tried to run VBA application on someone else's computer, but I get an
I tried to run this code: #define ROW_CNT 8; #define COLUMN_CNT 24; #define FIRST_COLUMN
I just tried to run my company's app in the new x86 android emulator,
This problem was discovered when I tried to run the Android emulator in Eclipse.
hey i followed a ruby on rails guide when i tried to run it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.