SQL-Server 2005: 无法绑定多部分标识符

SQL-Server 2005: multi-part identifier could not be bound

我正在使用 SQL Server 2005,我是 SQL 的新手,请多多包涵。

以下带别名的 SQL 查询出现以下错误:

The multi-part identifier "EquipmentDescription.DESCRIPTION" could not be bound.

SQL:

WITH somerows as 
(
    SELECT 
        Mastertable.ID, Mastertable.foo1, Mastertable.foo2, 
        Mastertable.foo3, EquipmentDescription.DESCRIPTION,
        ROW_NUMBER() OVER (ORDER BY Mastertable.ID) AS SeqValue 
    FROM 
        EquipmentDescription 
    LEFT JOIN 
        MasterTable ON EquipmentDescription.foo1 = MasterTable.foo1 
    ORDER BY 
        EquipmentDescription.DESCRIPTION
) 
SELECT * 
FROM somerows  
WHERE SeqValue BETWEEN 0 and 20

背景:Mastertable 有 60,000 多条记录。我正在使用 WITH...as...etc 在服务器端一次请求 20 条记录。

为了设计目的,EquipmentDescriptionDESCRIPTION列未包含在Mastertable中。要求在最后的 select.

中包含 DESCRIPTION

对我做错了什么有什么想法吗?

这个有效:

SELECT * FROM 
(
SELECT 
    ROW_NUMBER() OVER(ORDER BY ID) AS NUMBER,
    Mastertable.ID, Mastertable.foo1, Mastertable.foo2, 
    Mastertable.foo3, EquipmentDescription.DESCRIPTION,
FROM 
    EquipmentDescription 
RIGHT JOIN 
    MasterTable ON EquipmentDescription.foo1 = MasterTable.foo1
) AS t_MasterTable 
WHERE
    NUMBER BETWEEN 0 and 20
ORDER BY ID