解决“无法绑定多部分标识符"的问题SQL Server 中的错误 [英] Solve "The multi-part identifier could not be bound" error in SQL Server

查看:23
本文介绍了解决“无法绑定多部分标识符"的问题SQL Server 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

解决方案是什么?

推荐答案

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

You have a cross join between tblUserLoginDetail and tblInvoicePaymentDetails in the FROM clause, so you can't use l.loginid in the FROM clause

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

I think what you want is this with an explicit INNER JOIN. I'e also separated filter and join conditions:

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

这篇关于解决“无法绑定多部分标识符"的问题SQL Server 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆