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
 Select x Record based on row passed in URL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

assunta
Starting Member

3 Posts

Posted - 08/03/2007 :  04:30:20  Show Profile  Reply with Quote
Hi all - this one has me stumped... PLEASE HELP!!!

I have a back/forward navigation link that passes a URL.startrow number (lets call it n) - based on n - I only want to select the record that is the n'th record based on a sort order (gall_order) - (SQL SERVER).

<cfquery name="gallHomePic1st" datasource="id" maxrows="1">
SELECT id
FROM gall_home
ORDER BY gall_order asc

</cfquery>

For e.g. - I want the 7th (14th - 21st etc) record based on gall_order asc.

Thanks guys - this has me stumped!

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 08/03/2007 :  04:39:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Add a WHERE clause

WHERE gall_order > @n



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

assunta
Starting Member

3 Posts

Posted - 08/03/2007 :  05:01:16  Show Profile  Reply with Quote
Wont work - the sort_order has nothing to do with URL.startrow - this drives a thumb gallery - when you select a thumb - it pass an id through the url which in turn is retreaved by another sql query (select id from gall_home where id = URL.id). The problem is, when the user clicks 'next' to retriev the next group of thumbnails - I want the image to reflect the first thumb in this new group - hence why I nedd the '7th(14th,21st,etc)' record id. Any other ideas??? Can this be done in sql or do I need to play around with some funky coldfusion to achieve this?

Thanks
Go to Top of Page

cvraghu
Posting Yak Master

India
187 Posts

Posted - 08/03/2007 :  14:45:52  Show Profile  Reply with Quote
Did you tried using Row_Number function? Please look into Book online for more help.

SELECT id, ROW_NUMBER() OVER (order by gall_order asc)
FROM gall_home
WHERE RowNumber = n
Go to Top of Page

KenW
Constraint Violating Yak Guru

USA
391 Posts

Posted - 08/03/2007 :  14:47:48  Show Profile  Reply with Quote
assunta,

Search this site for "paging". You'll find several dozen answers.
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.06 seconds. Powered By: Snitz Forums 2000