Avatar of goodk
goodk
Flag for United States of America asked on

What is the best way to paginate where I can pass my existing sql statement as a variable

so existing mySQLStatement could be passed in as a variable to a c# function?

mySQLStatement="Select field1,field2 from myTable";

myNewSQLwithPagination=convertsqltopaginationsql(mySQLStatement,PageStartNumber,PageStopNumber)

Basically I am asking how to generalize pagination by passing simple queries?

I use mssql
Web Languages and StandardsDatabasesC#ASP.NETSQL

Avatar of undefined
Last Comment
goodk

8/22/2022 - Mon
goodk

ASKER
Ok, in other words

I want to build a generalized function where I pass sql statement and and page start and page size and it returns the sql statement which does pagination.
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
goodk

ASKER
I liked the link but I could not quite gather how I would use to crate a generalized function?
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
goodk

ASKER
Please see my original question.  If any one has an answer.  I am sure many people had written a function of the sort otherwise one has to write each and every query for pagination.
Your help has saved me hundreds of hours of internet surfing.
fblack61
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
goodk

ASKER
How MS access does paging as we only submit a simple sql?
SOLUTION
EugeneZ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pravin Asar

With MYSQL , you can use limit and startpoint

e.g.
SELECT * FROM tblOrders  ORDER BY datetime ASC LIMIT 1 , 20";


With MSSQL, you can use ROW_NUMBER()

SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, *
          FROM      Orders
          WHERE     OrderDate >= '1980-01-01'
        ) AS RowConstrainedResult
WHERE   RowNum >= 1
    AND RowNum < 21
ORDER BY RowNum
Pravin Asar

Important aspect in paging is have sort criteria.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Pravin Asar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
goodk

ASKER
I am not sure if I got the answer I was looking for.  I am using MSSQL shared database on godaddy.com

my front end is asp.net  using VWD from MS