I am trying to create a tag based image viewer for my site. When a user clicks a photo from the thumbnail page it will pass the image ID and tag that thumbnail belonged to. I would like to pass that imageID and tagname to a stored procedure and return the previous and next imageID's. If the image ID hits a hard limit, (ie: the passed ID was the first or last in the query), it would return zero.
I am pretty familiar with SQL and played around with the row_number function a bit but not really getting far.