【问题标题】:Solve "The multi-part identifier could not be bound" error in SQL Server解决 SQL Server 中“无法绑定多部分标识符”错误
【发布时间】:2011-10-12 14:00:58
【问题描述】:
select distinct 
  l.username,
  p.payid,
  p.paymentdate,
  sum(p.paymentamount) as payment,
  b.balance as balance 
from 
  tblUserLoginDetail l,
  tblInvoicePaymentDetails p 
  left outer join tblPaymentCustomerBalance b 
    on p.accountnumber=10009 
    and p.payid=b.payid 
    and p.customerid=l.loginid
  group by  p.payid,p.paymentdate,b.balance,l.username

错误是:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "l.loginid" could not be bound.

解决办法是什么?

【问题讨论】:

    标签: sql-server-2005


    【解决方案1】:

    FROM 子句中的 tblUserLoginDetail 和 tblInvoicePaymentDetails 有交叉连接,所以不能在 FROM 子句中使用 l.loginid

    我认为您想要的是带有显式 INNER JOIN 的内容。我还分离了过滤器和连接条件:

    select
        l.username,
        p.payid,
        p.paymentdate,
        sum(p.paymentamount) as payment,
        b.balance as balance
    from
        tblUserLoginDetail l
        inner join
        tblInvoicePaymentDetails p On p.customerid=l.loginid 
        left outer join
        tblPaymentCustomerBalance b ON p.payid=b.payid
    where
        p.accountnumber=10009
    group by
       p.payid,p.paymentdate,b.balance,l.username
    

    【讨论】:

    • 先生基于 10009 账户支付表 3 条记录 r 但 customerbalance 表有 1 条记录,我有 3 条记录,在 customertable 的剩余记录中余额为 0
    • @hmk:这与您提出的问题无关
    猜你喜欢
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多