SQL错误1016-内部联接
我正在尝试向旧的SQL代码添加内部连接,以使其运行更高效。但当我添加它们并尝试执行时,我得到了以下错误: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
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
行是否造成了问题;您是否尝试删除它以查看是否仍然出现错误?有趣的是,您的重新写入清楚地表明,所有连接也由参数指定。这成功了!现在它似乎移动得更快了!非常感谢!通过比较您所做的和我以前所做的,我实际上学到了更多关于连接的知识…再次感谢!!有趣的是,您的重写清楚地表明,所有连接也由参数指定。这就成功了!现在它似乎移动得更快了!非常感谢!通过比较您所做的和我以前所做的,我实际上学到了更多关于连接的知识…再次感谢!!