Click here to Skip to main content
15,923,273 members
Home / Discussions / Database
   

Database

 
GeneralRe: Get databases Pin
Syed Mujtaba Hassan2-Sep-07 22:42
Syed Mujtaba Hassan2-Sep-07 22:42 
Questionlogin problem in sql server express Pin
prasadbuddhika2-Sep-07 17:50
prasadbuddhika2-Sep-07 17:50 
AnswerRe: login problem in sql server express Pin
M LN Rao2-Sep-07 21:32
M LN Rao2-Sep-07 21:32 
AnswerRe: login problem in sql server express Pin
John Gathogo3-Sep-07 20:28
John Gathogo3-Sep-07 20:28 
QuestionSQL Order By in paging algorithim Pin
Polymorpher2-Sep-07 11:50
Polymorpher2-Sep-07 11:50 
AnswerRe: SQL Order By in paging algorithim Pin
Colin Angus Mackay2-Sep-07 12:04
Colin Angus Mackay2-Sep-07 12:04 
GeneralRe: SQL Order By in paging algorithim Pin
Polymorpher2-Sep-07 15:50
Polymorpher2-Sep-07 15:50 
GeneralRe: SQL Order By in paging algorithim Pin
Colin Angus Mackay2-Sep-07 22:54
Colin Angus Mackay2-Sep-07 22:54 
Polymorpher wrote:
SET ROWCOUNT is set back to 0 at the end to restore it for latter query's. An explanation of why I'm using SET ROWCOUNT can be found here:

http://www.4guysfromrolla.com/webtech/042606-1.shtml[^]

It is a fairly efficient way of doing this...


Maybe, but it is also a fairly dangerous thing to do. SET ROWCOUNT will affect other queries running at the same time. If you are never going to have other users then this is fine. But in that case why are you using something like SQL Server.

As for incorportating an order. Use subquerys - If you expect to be paging through lots of data then you may wish to use a temp table for the innermost SELECT. Also, remember to only use the columns you actually need, this will help the performance of the query rather than the demonstration SELECT * I've used here.

First lets, say you want rows 76 to 100 (25 rows in total). Get the first 100 rows
SELECT TOP 100 * 
FROM MyTable 
ORDER BY OrderColumn


Then Reverse the order of the result set getting only 25 rows
SELECT TOP 25 * 
FROM (SELECT TOP 100 * 
      FROM MyTable 
      ORDER BY OrderColumn)
ORDER BY OrderColumn DESC


Finally, flip the order back again:
SELECT *
FROM (SELECT TOP 25 *
      FROM (SELECT TOP 100 * 
            FROM MyTable 
            ORDER BY OrderColumn)
      ORDER BY OrderColumn DESC)
ORDER BY OrderColumn



Upcoming FREE developer events:
* Glasgow: Agile in the Enterprise Vs. ISVs, db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ...

My website

AnswerRe: SQL Order By in paging algorithim Pin
Colin Angus Mackay2-Sep-07 14:06
Colin Angus Mackay2-Sep-07 14:06 
GeneralRe: SQL Order By in paging algorithim Pin
Polymorpher2-Sep-07 15:51
Polymorpher2-Sep-07 15:51 
GeneralRe: SQL Order By in paging algorithim Pin
Colin Angus Mackay2-Sep-07 22:56
Colin Angus Mackay2-Sep-07 22:56 
Questioncount query Pin
Deian2-Sep-07 7:12
Deian2-Sep-07 7:12 
AnswerRe: count query Pin
Arjan Einbu2-Sep-07 11:18
Arjan Einbu2-Sep-07 11:18 
GeneralRe: count query Pin
Deian2-Sep-07 20:57
Deian2-Sep-07 20:57 
GeneralRe: count query Pin
Arjan Einbu2-Sep-07 21:29
Arjan Einbu2-Sep-07 21:29 
Questionwhat is the difference between roles Pin
prasadbuddhika1-Sep-07 16:45
prasadbuddhika1-Sep-07 16:45 
AnswerRe: what is the difference between roles Pin
Vasudevan Deepak Kumar2-Sep-07 0:51
Vasudevan Deepak Kumar2-Sep-07 0:51 
QuestionSQL 2005 Execute permissions Pin
mtone1-Sep-07 5:57
mtone1-Sep-07 5:57 
Questionerror!! Pin
Rharzkie1-Sep-07 1:44
Rharzkie1-Sep-07 1:44 
AnswerRe: error!! Pin
Vasudevan Deepak Kumar2-Sep-07 0:50
Vasudevan Deepak Kumar2-Sep-07 0:50 
AnswerRe: error!! Pin
Paul Conrad2-Sep-07 5:32
professionalPaul Conrad2-Sep-07 5:32 
Questioni can't connect in the connection wizard! Pin
Rharzkie1-Sep-07 0:45
Rharzkie1-Sep-07 0:45 
AnswerRe: i can't connect in the connection wizard! Pin
Vasudevan Deepak Kumar1-Sep-07 1:20
Vasudevan Deepak Kumar1-Sep-07 1:20 
QuestionAccess Not Saving Data (Sometimes...) Pin
Expert Coming31-Aug-07 13:30
Expert Coming31-Aug-07 13:30 
AnswerRe: Access Not Saving Data (Sometimes...) Pin
Vasudevan Deepak Kumar1-Sep-07 1:21
Vasudevan Deepak Kumar1-Sep-07 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.