【发布时间】:2014-02-13 00:08:35
【问题描述】:
我写了这个查询来获取特殊关键字的数据:
ALTER procedure [dbo].[GetAllSpecialPaperTags]
@PKeyword nvarchar(200)
as
begin
select
Papers.PID, Papers.PTitle, Papers.PaperSummary
from
PaperKeywords
left join
PaperTags on PaperKeywords.PKeyID = PaperTags.PKeyID
left join
Papers on PaperTags.PID = Papers.PID
where
PaperKeywords.PKeyword = @PKeyword
end
我想使用这篇文章进行自定义分页:Custom Paging using SQL Server Stored Procedure
我写了这个查询,但我收到了一个错误:
create procedure [dbo].[GetAllSpecialPaperTags]
@PageIndex INT = 1
,@PageSize INT = 10
,@RecordCount INT OUTPUT
,@PKeyword nvarchar(200)
as
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [Papers.PID] ASC
)AS RowNumber
,Papers.PID , Papers.PTitle , Papers.PaperSummary
INTO #Results
from PaperKeywords
left join PaperTags on PaperKeywords.PKeyID = PaperTags.PKeyID
left join Papers on PaperTags.PID = Papers.PID where PaperKeywords.PKeyword = @PKeyword
SELECT @RecordCount = COUNT(*)
FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
end
错误:
消息 207,级别 16,状态 1,过程 GetAllSpecialPaperTags,第 11 行
列名“Papers.PID”无效。
为什么?
【问题讨论】:
标签: sql sql-server tsql