SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Paging of records using sql server stored procedur
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sparrow37
Posting Yak Master

148 Posts

Posted - 03/28/2013 :  04:35:22  Show Profile  Reply with Quote


I have a stored procedure which returns result from two tables using outer join and where conditions. It has order by clause as well. I want to add paging to it so that only requested number of records are returned. How can I do it? I need to supply pagenumber, totalnumber of records, current page etc ? My stored procedure is:

CREATE PROCEDURE [dbo].[hr_SearchVacanciesForService]

@SearchText NVARCHAR(50) = NULL,
@DutyStationID INT = NULL,
@VacancyCategoryIDs VARCHAR(1000) = NULL,
@Language INT = 1
AS

SELECT *
FROM dbo.hr_Vacancies LEFT OUTER JOIN dbo.hr_DutyStations ON dbo.hr_Vacancies.DutyStationID = dbo.hr_DutyStations.DutyStationID
LEFT OUTER JOIN dbo.hr_Companies
ON dbo.hr_Vacancies.CompanyID = dbo.hr_Companies.CompanyID
WHERE dbo.hr_Vacancies.Deleted = 0
AND (dbo.hr_Vacancies.JobTitleLang1 LIKE @LoacalSeacrchText
OR dbo.hr_Vacancies.JobTitleLang2 LIKE @LoacalSeacrchText
OR dbo.hr_Vacancies.DescriptionLang1 LIKE @LoacalSeacrchText
OR dbo.hr_Vacancies.DescriptionLang2 LIKE @LoacalSeacrchText
AND (dbo.hr_Vacancies.DutyStationID = @DutyStationID OR @DutyStationID IS NULL OR @DutyStationID = 0)
ORDER BY HavePriority DESC, StartDate DESC, dbo.hr_Vacancies.VacancyID DESC

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 03/28/2013 :  04:48:52  Show Profile  Reply with Quote
http://www.sqlteam.com/article/server-side-paging-using-sql-server-2005


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/28/2013 :  04:50:19  Show Profile  Reply with Quote
what will be values you pass for pagenumber, totalnumber of records, current page etc? whats the difference between pagenumber and current page?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000