How can I fix this error:
Msg 156, Level 15, State 1, Procedure inventory, Line 6 [Batch Start Line 2]
Incorrect syntax near the keyword 'Where'
This is my code
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
You need to define the join condition between your tables:
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
From item pickup)))
If there is a space in the table name item pickup, which is not best practice, then you need to surround the name in square brackets [item pickup].
And to expand on jaime's post, it would also help to use table aliases to define the tables, and used them in columns, so if there are columns in both tables with the same name then SQL Server knows which table_name.column_name you are referring to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.