iso*_*owl 2 sql sql-server error-handling boolean
我很厌倦看到这个错误:
消息102,级别15,状态1,过程sp_reorder_quantity,第16行
' - '附近的语法不正确.
它说明了这一点,因为它在第16行说明:
WHERE products.quantity_in_stock – products.reorder_level < @unit;
Run Code Online (Sandbox Code Playgroud)
它的意思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
Run Code Online (Sandbox Code Playgroud)
这可能只是自动格式化搞砸了,但是–("en dash",U + 2013)与-("hyphen-minus",U + 002D)不是同一个字符.
尝试将其更改为:
WHERE products.quantity_in_stock - products.reorder_level < @unit;
Run Code Online (Sandbox Code Playgroud)
如果我把它们放在彼此旁边,这更容易看出:
WHERE products.quantity_in_stock – products.reorder_level < @unit; -- yours
WHERE products.quantity_in_stock - products.reorder_level < @unit; -- fixed
Run Code Online (Sandbox Code Playgroud)