Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
matrixr
Starting Member
26 Posts |
Posted - 2006-07-21 : 02:50:48
|
| at the moment im using the paging technique described http://www.aspfaq.com/show.asp?id=2120 (ROW COUNT method) all works fine now what i want to do is order a certain page by a column asc/descthis is how i do it nowdeclare @t table (...columns...)insert into @t select ...columns from ...select * from @t order by xyzi cannot use a sub query because mssql says order by is not valid for a subquery, i cannot use the top 100 percent trick because then it screws up the paging techniquethere must be a better way to do this, any ideas?thanks |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
|
|
matrixr
Starting Member
26 Posts |
Posted - 2006-07-21 : 06:00:43
|
| perfectdeclare @page int, @pageSize int, @totalRows int, @offset intselect @page = 0, @pageSize = 5select @totalRows = count(*) from table [optional where clause]select @offset = @totalRows - (@pageSize * @page)execute ('select * from (select top ' + @pageSize + ' * from (select top ' + @offset + ' * from table [optional where clause] order by [column(s)] desc) a order by [same column(s) as above] asc) border by [same column(s) as above] asc')that did the trick.thanks |
 |
|
|
|
|
|