..............
declare @sql varcahr(8000)set @sql='insert @t_table
(
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
)
SELECT
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
FROM t_info where '''+@searchcondition+''' like '%'''+@searchwhat+'''%'
ORDER BY [Info_Date]'exec (@sql)
....
declare @sql varcahr(8000)set @sql='insert @t_table
(
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
)
SELECT
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
FROM t_info where '''+@searchcondition+''' like '%'''+@searchwhat+'''%'
ORDER BY [Info_Date]'exec (@sql)
....
@StartRow as int = null,
@StopRow as int = null,
@searchcondition as varchar(100),
@searchwhat as varchar(100)
AS
declare @a varchar(10)
set @a=@StartRow
---- 在返回指定的@StopRow行数之后停止处理查询
Set RowCount @StopRowexec('
---- 建立有标识符列的table变量
declare @t_table table
(
[rownum] [int] IDENTITY (1, 1) Primary key NOT NULL ,
[Info_ID] [int],
[Info_Content] [text],
[Info_Title] [varchar] (255),
[Info_Author] [varchar] (50),
[Info_Date] [datetime],
[Info_hits] [int],
[Info_Level] [int],
[Info_Img] [varchar] (255) ,
[Info_gflag] [bit]
)---- 插入到table变量中
insert @t_table
(
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
)
SELECT
[Info_ID],[Info_Content],[Info_Title],[Info_Author],[Info_Date],[Info_hits],[Info_Level],[Info_Img],[Info_gflag]
FROM t_info where ['+@searchcondition+'] like ''%'+@searchwhat+'%''
ORDER BY [Info_Date]---- 返回到正确的结果
SELECT * FROM @t_table WHERE rownum >= '+@a+'
ORDER BY rownum')
GO