Question

SELECT SKU
FROM PartProductSupplemental
EXCEPT
SELECT SKU
FROM Inventory

Why do I get this error:

Incorrect Syntax near the Word Except

I check on line and syntax is syntactically correct:

SELECT ProductID 
FROM Production.WorkOrder
EXCEPT
SELECT ProductID 
FROM Production.Product
Was it helpful?

Solution

Your database compatibility mode is probably set to 2000 (80) or earlier.

In Management Studio:

  1. Right click on the database name under the "Databases" heading in the Object Explorer
  2. In the Properties window that pops up, select "Options" - Compatibility Level is third from the top, on the right.

OTHER TIPS

When I run the following it works fine:

with PartProductSupplemental as
(
  SELECT 1 sku
  UNION
  select 2
  UNION
  SELECT 3
  UNION
  select 4
  UNION 
  SELECT 5
),
Inventory as
(
  SELECT 1 sku
  UNION
  select 2
  UNION
  SELECT 3

)

SELECT SKU
FROM PartProductSupplemental
EXCEPT
SELECT SKU
FROM Inventory

Are you sure this is actually what you are running? Is there any sql above that?

try using distinct and MINUS just to test.

Except should have worked as well, are the fields of the same type ?

(it works also on 2005, according to documentation and you don't need () on the 2nd phrase).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top