我正在尝试将内部联接添加到旧的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有关吗?
答案 0 :(得分:1)
INNER JOIN
和LEFT JOIN
替换您的表格之间的逗号
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
答案 1 :(得分:0)
如果在将其转换为ANSI语法后在代码中保留了“* =”连接运算符,则可以解释您的错误。当使用ANSI语法时,使用=进行所有相等性测试 - JOIN
声明本身(JOIN
,INNER
,LEFT
中RIGHT
的类型应该是明确的等等。)