【发布时间】:2018-02-28 05:00:30
【问题描述】:
此查询为数据表提供排序、过滤和分页。在我添加 INNER JOIN 之前,所有功能都运行良好,然后我得到:
The multi-part 'identifier "Types.Description" could not be bound
如果我在查询末尾删除第二个WHERE 子句,LIKE 语句有效,但我失去了分页。我删除了一些 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
【问题讨论】:
标签: sql join pagination sql-like