SQL-Server

Moderators: None (Apply to moderate this forum)
Number of threads: 423
Number of posts: 776

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem Paging Results with MSSQL / PHP Posted by kdc_landrover on 29 Oct 2009 at 4:41 AM
Hi, I’m working on a website for a recruitment company, and am having some problems with paging results using MSSQL.

After doing some research I understand that you need to use a nested TOP query (something like this: http://josephlindsay.com/archives/2005/05/27/paging-results-in-ms-sql-server/), but have been unable to get this to work with our large query below which pulls data from multiple tables. Essentially all this query is pulling is the following: job title, salary, location, job type, date posted, description, consultants email address. This covers 5 different tables as a result of the local front end software package, which was built in conjunction with these tables.

SELECT 
EmploymentTypes.Description AS JobType, Jobs.JobTitle, Jobs.JobId, Jobs.JobRefNo, Jobs.LocationId, Jobs.PublishedJobDescription, Jobs.UpdatedOn, Jobs.Salary, Locations.Description, Users.EmailAddress
FROM 
Jobs, Locations, Users, JobConsultants, EmploymentTypes    
WHERE 
Jobs.Published = 'Y' 
AND (EmploymentTypes.EmploymentTypeId = Jobs.EmploymentTypeId) 
AND (JobConsultants.UserId = Users.UserId) 
AND (Jobs.JobId = JobConsultants.JobId) 
AND (Locations.LocationId = Jobs.LocationId) 
AND (JobConsultants.UserRelationshipId = '9')  
ORDER BY ".$sql_ordertemp."


Can anyone show me how to modify the above query to incorporate the nested TOP statement? I assume that the TOP values will be substituted with PHP variables?

Any help would be greatly appreciated! Thanks…

Report
Re: Problem Paging Results with MSSQL / PHP Posted by kiddo13 on 15 Jul 2010 at 10:46 AM
If you want to query from different tables, you must define the relationship within the tables. To do that you can use INNER JOIN, not WHERE condition.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.