Hi,I've a procedure that lists entities with a certain filter given by the application.The result set is an entities' list with the Id and other fields. The app stores just the filter and when an entity is opened it also stores it's id. The purpose is to have a Next and Previous navigation on the entity data but since we only have the id and the filter I'd like to know if there's an easy and fast way of "filtering" the list with the id and get the next and previous record id...List example:[code="SQL"]SELECT id, name, phone, address FROM entities WHERE phone LIKE @phone AND idCountry = @idCountry ORDER BY name OFFSET ((@pageNumber - 1) * @numRecords) ROWS FETCH NEXT @numRecords ROWS ONLY[/code]The navigation example would be something like:[code="SQL"]SELECT id, [...] previousId, [...] nextId FROM entities WHERE phone LIKE @phone AND idCountry = @idCountry AND id = @id ORDER BY name [/code]The LAG and LEAD should do the work but since I'm filtering the id the result set only has one record they return NULL...If we had full "control" of the application the list could return the record position and I would search the position - 1 and + 1 but we can't control the classes...Thanks,Pedro
↧