sp_executesql 语句的问题
本帖最后由 yyixin 于 2014-01-23 21:10:40 编辑
exec sp_executesql N'
SELECT * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY @strOrder) AS pos,@strGetFields
FROM [MemberAlbum] @strWhere) AS sp
WHERE pos BETWEEN (@PageIndex-1)*@PageSize+1) AND @PageIndex*@PageSize',
N'@strWhere varchar(250),@strOrder varchar(250),@strGetFields varchar(250), @PageIndex int,@PageSize int',
@strWhere='WHERE ID>10',@strOrder='EditTime DESC',@strGetFields='*',@PageIndex=1,@PageSize=20
declare @tsql varchar(6000),@strWhere varchar(250),@strOrder varchar(250),@strGetFields varchar(250),@PageIndex int,@PageSize int
select @strWhere='WHERE ID>10',
@strOrder='EditTime DESC',
@strGetFields='*',
@PageIndex=1,
@PageSize=20
select @tsql='SELECT * FROM '
+' (SELECT ROW_NUMBER() OVER (ORDER BY '+@strOrder+') AS pos,'+@strGetFields
+' FROM [MemberAlbum] '
+ @strWhere+') AS sp '
+'WHERE pos BETWEEN '+rtrim((@PageIndex-1)*@PageSize+1)
+' AND '+rtrim(@PageIndex*@PageSize)
exec(@tsql)