473,396 Members | 1,767 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,396 software developers and data experts.

Stored Procedure Paging

MEM
I'm fairly new to sql stored procedures. ok, I currently have a stored
procedure that dynamically sorts as well as pages through a recordset:
__________________________________________________ _________________________

PROCEDURE dbo.ViewAllSales

@Page int,
@RecsPerPage int,
@SortSQL varchar(100),
@varSession_ID varchar(4),
@varFirstDayMonth_Date datetime,
@varCurrentDayMonthOrder_Date datetime
AS
BEGIN
SET NOCOUNT ON

CREATE TABLE #TempViewSales
(
SalesAutoID int IDENTITY,
TransID int
)

DECLARE @SearchSQL varchar(4000)

SELECT @SearchSQL = 'INSERT INTO #TempViewSales (TransID)' +
' SELECT Transaction_ID FROM tblTransactions WHERE Session_ID =
' + @varSession_ID +
' AND Order_Date >= ''' + Convert(varchar(25),
@varFirstDayMonth_Date, 121) + ''' AND Order_Date <= ''' +
Convert(varchar(25), @varCurrentDayMonthOrder_Date, 121) + '''AND
Active <> 0 ORDER BY ' + @SortSQL
EXECUTE(@SearchSQL)

DECLARE @FirstRec int, @LastRec int

SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

SELECT *, MoreRecords = (SELECT COUNT(*) FROM #TempViewSales WHERE
SalesAutoID >= @LastRec)
FROM #TempViewSales INNER JOIN tblTransactions ON
tblTransactions.Transaction_ID = #TempViewSales.TransID
WHERE SalesAutoID > @FirstRec AND SalesAutoID < @LastRec
SET NOCOUNT OFF
END

__________________________________________________ _________________________

How do i return a record count? And how would i implement a "page x of
y" sceanario? Thanks in advance.
Jul 20 '05 #1
0 3817

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

Similar topics

7
by: Vitamin | last post by:
I have written a stored procedure which will paging the recordset, and return a range of record that i need, and i write a asp code to call it however, no any return after the set objRs =...
7
by: Alex Vorobiev | last post by:
hi there, i am using sql server 7. below is the stored procedure that is giving me grief. its purpose it two-fold, depending on how it is called: either to return a pageset (based on page...
2
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
7
by: Jerry | last post by:
I'm trying to execute a stored procedure in a loop while paging through database table records but the stored procedure isn't running. I get the folowing error: The component 'adodb.connection'...
0
by: sck10 | last post by:
Hello, How do you turn on paging on a GridView? I am binding a stored procedure in my code file using the following: OracleDataReader sdrSearch = cmdSearch.ExecuteReader();...
1
by: Sureshbari | last post by:
Dear All, I have four table in database , each table contain the 5 lacs record, i have created a view on that four table using union clause. and now i am call that view form my code like ...
2
by: santyonline123 | last post by:
Hi Friends, I have to create paging using oracle stored procedure for a c#.net application.I have to develop this application without using cursor. I tried following procedure but its giving...
1
by: WebNewbie | last post by:
Hi, I am new to using mysql and there isn't any tutorials online on that shows how to create mysql stored procedure for paging purposes. Thus, I read tutorials on creating stored proc that were...
2
by: Bob Barrows [MVP] | last post by:
Paolo Galli wrote: You should probably read here to see some more efficient techniques (this article does contain the answer to your problem even if you are not interested in using a different...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.