sql字段排序问题
表结构
BookID BookName WeekClicks MonthClicks TotolClicks
asp.net的页面中有三个按钮分别是按周排序,按月排序,按总量排序 不需要分页只显示点击的前50条数据 能否用一个存储过程来实现.
我写的代码如下 但是不正确 请高手指点 多谢
alter PROCEDURE [dbo].[sp_Book_GetTopBookList]
(
@ListCount int, /*显示数量参数*/
@TopType varchar(50)/*传递排序类别参数*/
)
AS
Begin
SET ROWCOUNT @ListCount
Select Bookname,BookID,WeekClicks, MonthClicks ,TotolClicks From Book Order by @TopType desc
End
[解决办法]
alter PROCEDURE [dbo].[sp_Book_GetTopBookList]
(
@ListCount int, /*显示数量参数*/
@TopType varchar(50)/*传递排序类别参数*/
)
AS
Begin
SET ROWCOUNT @ListCount
exec ( 'Select Bookname,BookID,WeekClicks, MonthClicks ,TotolClicks From Book Order by '+@TopType+ ' desc ')
End
你试试动态SQL行不~~