首页 新闻 会员 周边 捐助

排序参数的问题

0
悬赏园豆:20 [已解决问题] 解决于 2008-06-02 18:51
exec sp_executesql N'WITH SearchResult AS <BR>(&nbsp;&nbsp; SELECT Row_Number() OVER (ORDER BY&nbsp; @SortExpression +'' '' + @SortDirection) AS RowID, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UserID,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FirstName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UserName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UserRole<BR>&nbsp;&nbsp;&nbsp; FROM dbo.Users<BR>&nbsp;&nbsp;&nbsp; WHERE (Status = @Status OR @Status = -1) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND (FirstName LIKE <A href="mailto:''%''+@Keyword+''%''">''%''+@Keyword+''%''</A> OR LastName LIKE <A href="mailto:''%''+@Keyword+''%''">''%''+@Keyword+''%''</A> OR UserName LIKE <A href="mailto:''%''+@Keyword+''%''">''%''+@Keyword+''%''</A> OR&nbsp; @Keyword = '''')<BR>) SELECT * FROM SearchResult WHERE RowID &gt; @PageIndex * @PageSize AND RowID &lt;= (@PageIndex + 1) * @PageSize',<BR><A href="mailto:N'@Keyword">N'@Keyword</A> nvarchar(4000),@Status int,@PageIndex int,@PageSize int,@SortExpression nvarchar(8),@SortDirection nvarchar(4)',<BR>@Keyword=N'',@Status=-1,@PageIndex=0,@PageSize=1,@SortExpression=N'USERNAME',@SortDirection=N'asc'<BR>在上面的SQL语句中指定的排序参数 @SortExpression @SortDirection为什么不起作用,无论@SortDirection=N'asc'还是@SortDirection=N'desc',执行的结果始终是一样的顺序?
Leox的主页 Leox | 菜鸟二级 | 园豆:461
提问于:2008-01-15 09:38
< >
分享
最佳答案
0
这句中.你只是对RowID的获取中ORDER BY了.而整条SELECT DDL好象并没有做任何ORDER BY操作. 试一下在SELECT FROM WHERE后面加上ORDER BY.
Kenneth Byron | 小虾三级 |园豆:570 | 2008-01-15 10:31
其他回答(1)
0
排序条件应该加在选择语句的最后吧,改下顺序看看
niugm | 园豆:1685 (小虾三级) | 2008-01-15 10:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册