|
发表于 2020-6-1 22:30:01
|
显示全部楼层
--try
ALTER PROCEDURE dbo.VerseLogPaging
@SortColumn as varchar(100) = null,
@StartRow as int = null,
@StopRow as int = null
AS
declare @sql varchar(8000)
---- 建立有标识符列的table变量
set @sql='
declare @t_table table
(
[rownum] [int] IDENTITY (1, 1) Primary key NOT NULL ,
[SortColumn] [varchar] (40) ,
[VerseNumber] [varchar] (20) ,
[SubmitTime] [datetime],
[VerseText] [varchar] (500) ,
[UserID] [varchar] (20)
)
'
---- 在返回指定的@StopRow行数之后停止处理查询
Set RowCount @StopRow
---- 插入到table变量中
set @sql=@sql+
'
insert @t_table
(
[VerseNumber],[SubmitTime],[VerseText],[UserID])
SELECT rtrim([VerseNumber]),[SubmitTime],[VerseText],[UserID]
FROM ConstructionVerseLog
order by ['+@SortColumn+'] '
---- 返回到正确的结果
set @sql=@sql+
' SELECT * FROM @t_table WHERE rownum >='+ @StartRow +
' ORDER BY rownum '
EXEC(@sql)
Set RowCount 0 --最好加上這句
/* SET NOCOUNT ON */
RETURN
|
|