Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Administering
»
Any thoughts on this process?
Any thoughts on this process?
Rate Topic
Display Mode
Topic Options
Author
Message
curious_sqldba
curious_sqldba
Posted Saturday, February 16, 2013 11:12 PM
Ten Centuries
Group: General Forum Members
Last Login: Yesterday @ 4:13 PM
Points: 1,172,
Visits: 2,687
This is more of generic programming question. We have a stored procedure which is used on many of our applications built using asp.net. The sp basically first gives total count of pages and then displays the records. I would like to NOT include the count in the sp because it is most expensive ( very bad design, i will tried my best to optimize didnt find much luck). Is there any other way this can be calculated like in asp.net or somewhere else?
Post #1420944
ChrisM@Work
ChrisM@Work
Posted Monday, February 18, 2013 1:21 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 5,618,
Visits: 10,990
sqldba_newbie (2/16/2013)
This is more of generic programming question. We have a stored procedure which is used on many of our applications built using asp.net. The sp basically first gives total count of pages and then displays the records. I would like to NOT include the count in the sp because it is most expensive ( very bad design, i will tried my best to optimize didnt find much luck). Is there any other way this can be calculated like in asp.net or somewhere else?
Please post the actual plan for the stored procedure.
“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.”
- Gail Shaw
For fast, accurate and documented assistance in answering your questions, please read
this article
.
Understanding and using APPLY, (I)
and
(II)
Paul White
Hidden RBAR: Triangular Joins
/
The "Numbers" or "Tally" Table: What it is and how it replaces a loop
Jeff Moden
Exploring Recursive CTEs by Example
Dwain Camps
Post #1421068
opc.three
opc.three
Posted Tuesday, February 19, 2013 5:23 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 12:39 PM
Points: 6,722,
Visits: 11,765
The sp basically first gives
total count of pages
and then displays the records.
Please define "total count of pages."
__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Believe you can and you're halfway there.
--Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler
--Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them.
--Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples.
--Giordy
Post #1421584
Steve Thompson-454462
Steve Thompson-454462
Posted Tuesday, February 19, 2013 8:23 AM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 276,
Visits: 1,476
I'm assuming that total number of pages is a presentation-level metric indicating that at a rate of
x
records per page, you'll need to link to, and maybe display a label that indicates there are,
y
total pages. In other words if you show 10 records per page and the data set has 100 rows, you'll have 10 pages.
If so, this can very easily be done in your .NET layer. If you're using ADO objects to extract the data you can easily do something like Datatable.Rows.Count to calculate the total number of rows returned (I believe you can use a similar Count function if you're using Linq). Divide the row count by number of rows per page (adjusting for any remainder, of course) and you should be good to go.
If my assumption of what you meant by page count is off, I apologize.
Post #1421672
curious_sqldba
curious_sqldba
Posted Tuesday, February 19, 2013 8:53 AM
Ten Centuries
Group: General Forum Members
Last Login: Yesterday @ 4:13 PM
Points: 1,172,
Visits: 2,687
Steve Thompson-454462 (2/19/2013)
I'm assuming that total number of pages is a presentation-level metric indicating that at a rate of
x
records per page, you'll need to link to, and maybe display a label that indicates there are,
y
total pages. In other words if you show 10 records per page and the data set has 100 rows, you'll have 10 pages.
If so, this can very easily be done in your .NET layer. If you're using ADO objects to extract the data you can easily do something like Datatable.Rows.Count to calculate the total number of rows returned (I believe you can use a similar Count function if you're using Linq). Divide the row count by number of rows per page (adjusting for any remainder, of course) and you should be good to go.
If my assumption of what you meant by page count is off, I apologize.
This is EXACTLY what i was looking for.Would you have a article for reference which will define the steps which you have mentioned?
Post #1421693
Steve Thompson-454462
Steve Thompson-454462
Posted Tuesday, February 19, 2013 9:58 AM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 276,
Visits: 1,476
sqldba_newbie (2/19/2013)
Steve Thompson-454462 (2/19/2013)
I'm assuming that total number of pages is a presentation-level metric indicating that at a rate of
x
records per page, you'll need to link to, and maybe display a label that indicates there are,
y
total pages. In other words if you show 10 records per page and the data set has 100 rows, you'll have 10 pages.
If so, this can very easily be done in your .NET layer. If you're using ADO objects to extract the data you can easily do something like Datatable.Rows.Count to calculate the total number of rows returned (I believe you can use a similar Count function if you're using Linq). Divide the row count by number of rows per page (adjusting for any remainder, of course) and you should be good to go.
If my assumption of what you meant by page count is off, I apologize.
This is EXACTLY what i was looking for.Would you have a article for reference which will define the steps which you have mentioned?
I'm not sure how your Data Access Layer is constructed. If you use the SQLClient library to talk to your SQL Server back-end, you can create a SQLDataAdapter and use that to fill a DataTable or DataSet (a container that holds multiple DataTables). Once you have a DataTable filled with the results of your SQLCommand, you can get the row count with DataTable.Rows.Count.
Here's a link to the MSDN page on using SQLDataAdapters:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter%28v=vs.71%29.aspx
.
Here's the page on System.Data.DataTable:
http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx
Note that if you're using a firehose-type construct to consume your data (e.g. a DataReader) you would not be able to get the row count without cursoring through the result set.
Post #1421737
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.