无法绑定多部分标识符
我在SO上看到过类似的错误,但我找不到解决问题的方法。我有一个SQL查询,如:
SELECT DISTINCT a.maxa , b.mahuyen , a.tenxa , b.tenhuyen , ISNULL(dkcd.tong, 0) AS tongdkcdFROM phuongxa a , quanhuyen b LEFT OUTER JOIN ( SELECT maxa , COUNT(*) AS tong FROM khaosat WHERE CONVERT(DATETIME, ngaylap, 103) BETWEEN 'Sep 1 2011' AND 'Sep 5 2011' GROUP BY maxa ) AS dkcd ON dkcd.maxa = a.maxaWHERE a.maxa <> '99' AND LEFT(a.maxa, 2) = b.mahuyenORDER BY maxa;
当我执行此查询时,错误结果为: 无法绑定多部分标识符“a.maxa”。为什么?
P / s:如果我将查询分成2个单独的查询,它运行正常。
SELECT DISTINCT a.maxa , b.mahuyen , a.tenxa , b.tenhuyenFROM phuongxa a , quanhuyen bWHERE a.maxa <> '99' AND LEFT(a.maxa, 2) = b.mahuyenORDER BY maxa;
和
SELECT maxa , COUNT(*) AS tongFROM khaosatWHERE CONVERT(DATETIME, ngaylap, 103) BETWEEN 'Sep 1 2011' AND 'Sep 5 2011'GROUP BY maxa;
慕桂英3389331
慕婉清6462132
相关分类