2014-07-22 51 views
0

此查詢通過排序,篩選和分頁提供數據表。所有功能工作正常,直到我加入了INNER JOIN,然後我得到:使用INNER JOIN和LIKE過濾的SQL分頁

The multi-part 'identifier "Types.Description" could not be bound

,如果我在查詢語句LIKE工作結束除去第二WHERE條款,但我失去分頁。我刪除了一些LIKE子句來嘗試清理這個怪異的查詢。

SELECT * 
FROM ( 
    SELECT ROW_NUMBER() OVER (ORDER BY TAG asc) AS RowNumber, * 
    FROM (
     SELECT (SELECT COUNT(*) FROM Instruments) AS TotalDisplayRows, (SELECT COUNT(*) FROM Instruments) AS TotalRows, Instruments.Tag, Instruments.Location, Instruments.Description, Types.Description As TypeDesc, Manufacturer.Name, Lease.Name as LeaseName, Facility.Name as FacName 
     FROM Instruments 
     INNER JOIN Types ON Instruments.Type = Types.ID 
     INNER JOIN Manufacturer ON Instruments.Manufacturer = Manufacturer.ID 
     INNER JOIN Facility ON Instruments.Facility = Facility.ID 
     INNER JOIN Lease ON Instruments.Lease = Lease.ID 
     WHERE (Types.Description LIKE '%Cat%') 
    ) RawResults 
) Results 
    WHERE (Types.Description LIKE '%Cat%') AND RowNumber BETWEEN 1 AND 10 

回答

0

我覺得這是你的問題

WHERE (types.description LIKE '%Cat%') 

你不能這樣做,因爲你實際上是從一個名爲Results派生表中選擇你使用了別名列TypeDesc

所以應該

WHERE (results.typeDesc LIKE '%Cat%') 
+0

這使我我的解決方案。謝謝!看起來很簡單..很有意義。 – Mason