如何修复此错误:
消息 156,级别 15,状态 1,过程库存,第 6 行 [批处理起始行 2]
关键字"Where"附近的语法不正确
这是我的代码
create view inventory ([name], [description], [price])
as
Select
name, description, MaxPrice
From
item
Join
ITEM_TYPE
Where
item_id not in (Select itemid
From ORDER_ITEM
Where itemid not in (Select ItemID
From ITEM_DONATION
Where itemid not in (Select itemid
From item pickup)))
Go
您需要定义表之间的连接条件:
create view inventory
(
[name]
, [description]
, [price]
)
as
Select
name
, description
, MaxPrice
From
item
join
ITEM_TYPE
on item.<YOUR_FIELD>=ITEM_TYPE.<YOUR_FIELD>
Where
item_id not in
(
Select
itemid
From
ORDER_ITEM
Where
itemid not in
(
Select
ItemID
From
ITEM_DONATION
Where
itemid not in
(
Select
itemid
From
item pickup
)
)
)
Go
从物品取货(((
如果表名称项拾取中存在空格(这不是最佳做法(,则需要将名称括在方括号 [item pickup] 中。
为了扩展 jaime 的文章,使用表别名来定义表并在列中使用它们也会有所帮助,因此如果两个表中都有同名的列,则 SQL Server 知道您指的是哪个 table_name.column_name。