2012-12-10 45 views
2

我太累了,看到這個錯誤的表達:在上下文指定的非布爾類型了條件,預計

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

它指出這一點,因爲在那裏指出第16行:

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

這就是說products.quantity_in_stock是: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 

回答

5

這可能只是自動格式化搞亂的東西,但( 「破折號」,U + 2013)是不一樣的字符作爲-( 「字號減」,U + 002D)。

嘗試將其更改爲:

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

這是比較容易看到,如果我把他們旁邊的海誓山盟:

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

哦,我的。對,就是這樣......我從電子郵件中複製了該行。謝謝! – isolatedhowl

0

您可以隨時改寫的路線爲:

WHERE     products.quantity_in_stock < products.reorder_level + @unit; 
相關問題