yavari
یک شنبه 09 مهر 1385, 14:34 عصر
سلام
میخوام پروسیجری بنویسم که رکوردای یه محدوده رو خروجی بده ضمن اینکه تعداد کل رکوردهای یافته شده رو هم داشته باشم! میشه همچین کاری کرد ؟ :متفکر:
اینم چند نمونه ای که نوشتم اما متاسفانه هیچکدوم جوابی رو که میخوام نمیده ! :گریه:
ممنون میشم راهنمائیم کنید !
CREATE PROCEDURE dbo.procGetPagedAllUseres
(
@CurrentPage int,
@PageSize int,
@TotalRecords int output
)
AS
SET NOCOUNT ON
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT *
FROM
Useres
WHERE
Radif > @FirstRec
AND
Radif < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM Useres
GO
CREATE PROCEDURE dbo.procGetPagedAllUseres
(
@CurrentPage int,
@PageSize int,
@TotalRecords int output
)
AS
SET NOCOUNT ON
--Create a temp table to hold the current page of data
--Add an ID column to count the records
CREATE TABLE #TempTable
(
ID int IDENTITY PRIMARY KEY,
Radif int
)
--Fill the temp table with the News data
INSERT INTO #TempTable
(
Radif
)
SELECT Radif
FROM Useres
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT *
FROM
#TempTable
WHERE
Radif > @FirstRec
AND
Radif < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM #TempTable
GO
میخوام پروسیجری بنویسم که رکوردای یه محدوده رو خروجی بده ضمن اینکه تعداد کل رکوردهای یافته شده رو هم داشته باشم! میشه همچین کاری کرد ؟ :متفکر:
اینم چند نمونه ای که نوشتم اما متاسفانه هیچکدوم جوابی رو که میخوام نمیده ! :گریه:
ممنون میشم راهنمائیم کنید !
CREATE PROCEDURE dbo.procGetPagedAllUseres
(
@CurrentPage int,
@PageSize int,
@TotalRecords int output
)
AS
SET NOCOUNT ON
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT *
FROM
Useres
WHERE
Radif > @FirstRec
AND
Radif < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM Useres
GO
CREATE PROCEDURE dbo.procGetPagedAllUseres
(
@CurrentPage int,
@PageSize int,
@TotalRecords int output
)
AS
SET NOCOUNT ON
--Create a temp table to hold the current page of data
--Add an ID column to count the records
CREATE TABLE #TempTable
(
ID int IDENTITY PRIMARY KEY,
Radif int
)
--Fill the temp table with the News data
INSERT INTO #TempTable
(
Radif
)
SELECT Radif
FROM Useres
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT *
FROM
#TempTable
WHERE
Radif > @FirstRec
AND
Radif < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM #TempTable
GO