简体   繁体   English

'。'附近的语法不正确 在SQL中

[英]Incorrect syntax near '.' in SQL

I'm trying to do a SQL query with creating a view on a database that I've made earlier. 我正在尝试通过在先前创建的数据库上创建视图来执行SQL查询。 On viewing tables with joins earlier it was working fine, however now when I'm trying to create a view I get a "Incorrect syntax near '.'" error message from the first INNER JOIN statement. 在使用联接查看表之前,它工作正常,但是现在,当我尝试创建视图时,从第一条INNER JOIN语句中收到“。'附近的语法不正确”错误消息。 Why would this occur? 为什么会发生这种情况?

CREATE VIEW vm_order_cost
AS
SELECT  orders.order_id,
    orders.order_date,
    products.product_id,
    customers.name,
    order_cost = (order_details.quantity * products.unit_price)
FROM orders
    INNER JOIN customers AS orders.customer_id = customers.customer_id
    INNER JOIN order_details AS orders.order_id = order_details.order_id
    INNER JOIN products AS order_details.product_id = products.product_id
WHERE order_id BETWEEN '10000' AND '10200'
GO

You should be using ON instead of AS : 您应该使用ON而不是AS

CREATE VIEW vm_order_cost
AS
SELECT  orders.order_id,
    orders.order_date,
    products.product_id,
    customers.name,
    order_cost = (order_details.quantity * products.unit_price)
FROM orders
    INNER JOIN customers ON orders.customer_id = customers.customer_id
    INNER JOIN order_details ON orders.order_id = order_details.order_id
    INNER JOIN products ON order_details.product_id = products.product_id
WHERE order_id BETWEEN '10000' AND '10200'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM