473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sql server 2000 paging

Hi all

I need to implmenet paging across different tables. The tables all
have a different name eg Data01, data02 data03 etc, however they are
columns which are common to each table, but each table also has some
unique columns

My questions is that I want to display data from any one of these
tables - I wont know which one until runtime, but since they contains
large amounts of data, I only want to display say 10 at a time. Also
the database is on sql server 2000 so I cant use RowNumber

I am thinking of using dynamic sql, so I would have a stored procedure
which takes the following:
selectClause - the fields to pull out
tablename - name of the table to get data from
whereClause - any filter criteria to apply
sortColumn - the column to sort on
sortDirection - the direction to sort on

Inside this stored procedure I would have ot build up some sql and
then execute it. I cant think of any other way to do it. Can anyone
suggest any pointers or alternative options?

Many thanks

Jun 27 '08 #1
2 1327
Have you considered normalizing your tables so that the common columns are
in one table with some identifier that allows you to join it with the now
unique tables data01, data02 and so on?

That aside, in your stored procedure, you can set a ROWCOUNT for your
dynamic SQL query. This means that you will need to calculate, either in
the SQL or in your calling code, what row numbers you need.

SET ROWCONT - http://msdn.microsoft.com/en-us/library/ms188774.aspx

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Ilyas" <il***@igsoftwaresolutions.co.ukwrote in message
news:51**********************************@f36g2000 hsa.googlegroups.com...
Hi all

I need to implmenet paging across different tables. The tables all
have a different name eg Data01, data02 data03 etc, however they are
columns which are common to each table, but each table also has some
unique columns

My questions is that I want to display data from any one of these
tables - I wont know which one until runtime, but since they contains
large amounts of data, I only want to display say 10 at a time. Also
the database is on sql server 2000 so I cant use RowNumber

I am thinking of using dynamic sql, so I would have a stored procedure
which takes the following:
selectClause - the fields to pull out
tablename - name of the table to get data from
whereClause - any filter criteria to apply
sortColumn - the column to sort on
sortDirection - the direction to sort on

Inside this stored procedure I would have ot build up some sql and
then execute it. I cant think of any other way to do it. Can anyone
suggest any pointers or alternative options?

Many thanks
Jun 27 '08 #2
If you want to do true paging on the database end then you will aso need
pageSize and pageNumber parameters, and yes, the only way to do it that I
know of is using dynamic SQL. I usually build a command similar to the
following for this task:

declare @sql nvarchar(max);
declare @startRow int;
set @startRow = @pageSize * @pageNumber;

set @sql = '
select top ' + convert(nvarchar, @pageSize) + ' *
from mytable
where primaryKeyField not in
(select top ' + convert(nvarchar, @startRow) + ' primarykeyField
from mytable)';

exec(@sql);

If you don't know the all the field names at the time of writing the stored
proc then dynamic SQL is also the only way.

If you just want to know how many rows there is on the stored proc so that
you can do the paging calculations on the web server you might as well
download the whole resultset into a DataSet, then bind a grid with it and
let the grid take care of the paging. Of course doing it in the server is
much more efficient for large resultsets.

Hope that helps,
Fernando L Rodriguez, MCP
"S.M. Altaf [MVP]" <sm*****@mNOSPAMsn.comwrote in message
news:C0**********************************@microsof t.com...
Have you considered normalizing your tables so that the common columns are
in one table with some identifier that allows you to join it with the now
unique tables data01, data02 and so on?

That aside, in your stored procedure, you can set a ROWCOUNT for your
dynamic SQL query. This means that you will need to calculate, either in
the SQL or in your calling code, what row numbers you need.

SET ROWCONT - http://msdn.microsoft.com/en-us/library/ms188774.aspx

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Ilyas" <il***@igsoftwaresolutions.co.ukwrote in message
news:51**********************************@f36g2000 hsa.googlegroups.com...
>Hi all

I need to implmenet paging across different tables. The tables all
have a different name eg Data01, data02 data03 etc, however they are
columns which are common to each table, but each table also has some
unique columns

My questions is that I want to display data from any one of these
tables - I wont know which one until runtime, but since they contains
large amounts of data, I only want to display say 10 at a time. Also
the database is on sql server 2000 so I cant use RowNumber

I am thinking of using dynamic sql, so I would have a stored procedure
which takes the following:
selectClause - the fields to pull out
tablename - name of the table to get data from
whereClause - any filter criteria to apply
sortColumn - the column to sort on
sortDirection - the direction to sort on

Inside this stored procedure I would have ot build up some sql and
then execute it. I cant think of any other way to do it. Can anyone
suggest any pointers or alternative options?

Many thanks

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lorax | last post by:
I'm on the IS team of a medium-sized non-profit with international reach. We're trying to make some decisions regarding our Web server and database server as we expand our web site to have more...
2
by: GG | last post by:
Hi, We have a prod server running on SQL server 2000 64 bit. It is a 4cpu server with 16GB of RAM. we have a maxmemory setting of 15.5GB for sql server. Inspite of 15GB being available for sql...
4
by: Manuel Alves | last post by:
Scenario: ASP 2.0 on XP pro dev machine works fine. Publishing to windows 2003 server worked OK until I included paging for a datagrid. On page load I cal sub binddata Private Sub...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
1
by: mrcraze | last post by:
Hi Everyone! We are using a cursor for paging results in SQL server, mainly due to the performance gains achieved when working with large results sets. We have found this to be of great benefit...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: rbg | last post by:
I am using derived tables to Page data on the SQL Server side. I used this link as my mentor for doing paging on the SQL Serverhttp://msdn2.microsoft.com/en-us/library/ms979197.aspx I wanted to...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.