Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL错误1016-内部联接_Sql_Sql Server_Inner Join - Fatal编程技术网

SQL错误1016-内部联接

SQL错误1016-内部联接,sql,sql-server,inner-join,Sql,Sql Server,Inner Join,我正在尝试向旧的SQL代码添加内部连接,以使其运行更高效。但当我添加它们并尝试执行时,我得到了以下错误: 1016, Line 12 Outer join operators cannot be specified in a query containing joined tables 问题是: select a.s_purchase_order as order_id, a.order_type, a.nobackorder, a.order_note, a.note, a.rqs

我正在尝试向旧的SQL代码添加内部连接,以使其运行更高效。但当我添加它们并尝试执行时,我得到了以下错误:

1016, Line 12 Outer join operators cannot be specified in a query containing joined tables
问题是:

select a.s_purchase_order as order_id, 
a.order_type, 
a.nobackorder, 
a.order_note, 
a.note, 
a.rqst_dlvry_date, 
b.customer_name ,
c.store_name,
(c.store_name + ',' + isnull(c.address1 + ',', ' ') +  isnull(c.city + ',', ' ') +  isnull(c.state_cd+ ',', ' ')  + isnull( c.zipcode, ' ')) as store_info, 
d.supplier_account
from VW_CustomerOrder a, Customer b, Store c, eligible_supplier d
where a.customer = c.customer
and a.store = c.store
and a.customer = b.customer
and c.customer *= d.customer
and c.store *= d.store
and a.supplier *= d.supplier
and a.purchase_order = @order_id
and a.customer = @customer_id
and a.store=@store_id
and a.supplier = @supplier_id

知道是什么引起的吗?我猜这和isnull有关吧?

你试过这个吗?它将表之间的逗号替换为
内部联接
左联接

select a.s_purchase_order as order_id, 
    a.order_type, 
    a.nobackorder, 
    a.order_note, 
    a.note, 
    a.rqst_dlvry_date, 
    b.customer_name ,
    c.store_name,
    (c.store_name + ',' + isnull(c.address1 + ',', ' ') +  isnull(c.city + ',', ' ') +  isnull(c.state_cd+ ',', ' ')  + isnull( c.zipcode, ' ')) as store_info, 
    d.supplier_account
from VW_CustomerOrder a
INNER JOIN Customer b
    ON a.customer = b.customer
INNER JOIN Store c
    ON a.customer = c.customer
    and a.store = c.store
LEFT JOIN eligible_supplier d
    ON c.customer = d.customer
    and c.store = d.store
    and a.supplier = d.supplier
where a.purchase_order = @order_id
    and a.customer = @customer_id
    and a.store=@store_id
    and a.supplier = @supplier_id

你试过这个吗?它将表之间的逗号替换为
内部联接
左联接

select a.s_purchase_order as order_id, 
    a.order_type, 
    a.nobackorder, 
    a.order_note, 
    a.note, 
    a.rqst_dlvry_date, 
    b.customer_name ,
    c.store_name,
    (c.store_name + ',' + isnull(c.address1 + ',', ' ') +  isnull(c.city + ',', ' ') +  isnull(c.state_cd+ ',', ' ')  + isnull( c.zipcode, ' ')) as store_info, 
    d.supplier_account
from VW_CustomerOrder a
INNER JOIN Customer b
    ON a.customer = b.customer
INNER JOIN Store c
    ON a.customer = c.customer
    and a.store = c.store
LEFT JOIN eligible_supplier d
    ON c.customer = d.customer
    and c.store = d.store
    and a.supplier = d.supplier
where a.purchase_order = @order_id
    and a.customer = @customer_id
    and a.store=@store_id
    and a.supplier = @supplier_id

如果在将“*=”联接运算符转换为ANSI语法后将其留在代码中,则可以解释错误。使用ANSI语法时,对所有相等性测试使用=如果在将代码转换为ANSI语法后在代码中保留“*=”联接运算符,则
联接的类型应在
联接
声明本身中明确(
内部
,等等)。

如果在代码中保留“*=”联接运算符,则可以解释错误。Use=用于使用ANSI语法时的所有相等性测试--
连接的类型应该在
连接
声明本身中明确(
内部
左侧
右侧
,等等)

那些真正应该用ANSI语法编写的,例如
内部连接
LEFT-OUTER-JOIN
RIGHT-OUTER-JOIN
语法,而不是在
WHERE
子句中。我也真诚地怀疑
store\u info
行是否造成了问题;您是否尝试删除它以查看是否仍然出现错误?这些确实应该使用ANSI语法编写,例如
内部联接
左外部联接
右外部联接
语法,而不是
WHERE
子句。我也真诚地怀疑
store\u info
行是否造成了问题;您是否尝试删除它以查看是否仍然出现错误?有趣的是,您的重新写入清楚地表明,所有连接也由参数指定。这成功了!现在它似乎移动得更快了!非常感谢!通过比较您所做的和我以前所做的,我实际上学到了更多关于连接的知识…再次感谢!!有趣的是,您的重写清楚地表明,所有连接也由参数指定。这就成功了!现在它似乎移动得更快了!非常感谢!通过比较您所做的和我以前所做的,我实际上学到了更多关于连接的知识…再次感谢!!