1

我正在尝试将内部连接添加到旧 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有关?

4

2 回答 2

1

你试过这个吗?它将表格之间的逗号替换为INNER JOINandLEFT 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
于 2012-08-02T20:05:11.053 回答
0

如果在将代码转换为 ANSI 语法后将 "*=" 连接运算符留在代码中,则可以解释您的错误。使用 ANSI 语法时,对所有相等测试使用 = —— 你的类型JOIN应该在JOIN声明本身中明确(INNER, LEFT,RIGHT等)

于 2012-08-02T20:50:29.950 回答