isolatedhowl
isolatedhowl

Reputation: 191

An expression of non-boolean type specified in a context where a condition is expected

I'm so tired of seeing this error:

Msg 102, Level 15, State 1, Procedure sp_reorder_quantity, Line 16
Incorrect syntax near '–'.

It states this because on line 16 where it states:

WHERE products.quantity_in_stock – products.reorder_level < @unit; 

It's saying that products.quantity_in_stock is: An expression of non-boolean type specified in a context where a condition is expected.

CREATE PROCEDURE sp_reorder_quantity
(
    @unit       int
)
AS
   SELECT
      products.product_id,
      suppliers.name,
      suppliers.address,
      suppliers.city,
      suppliers.province,
      'qty' = products.quantity_in_stock,
      products.reorder_level
   FROM
      suppliers
   INNER JOIN
      products ON suppliers.supplier_id = products.supplier_id
   WHERE
      products.quantity_in_stock – products.reorder_level < @unit;
GO

Upvotes: 2

Views: 1922

Answers (2)

Brendan Long
Brendan Long

Reputation: 54242

This may just be auto-formatting messing things up, but ("en dash", U+2013) is not the same character as - ("hyphen-minus", U+002D).

Try changing it to:

WHERE products.quantity_in_stock - products.reorder_level < @unit;

This is easier to see if I put them right next to eachother:

WHERE products.quantity_in_stock – products.reorder_level < @unit; -- yours
WHERE products.quantity_in_stock - products.reorder_level < @unit; -- fixed

Upvotes: 5

Gordon Linoff
Gordon Linoff

Reputation: 1269503

You can always rephrase the line as:

WHERE                   products.quantity_in_stock < products.reorder_level + @unit;

Upvotes: 0

Related Questions