>>>>select PK from table inner join (select TOP 50 * from MyTable where PK_VAL > nVar Order by PK_VAL) TopSQL on ... ;
>>>>UNION ALL ;
>>>>select TOP 50 * from MyTable where PK_VAL < nVar Order by PK_VAL DESC
>>>>
>>>>Would this idea work too?
>>>
>>>I will try and compare with Sergey's approach. Thank you.
>>
>>So, which approach worked?
>
>Sergey's suggestion worked perfectly. But I thank you for your suggestion too; I have not had a chance to try it since I stopped at success <g>.
I guess it should have also work. But I was thinking that Sergey's solution is probably more efficient since it doesn't involve a JOIN.
It's actually very nice to use select * from (select...), I don't see this syntax suggested here often.
But just for curiosity sake I would appreciate if you can try both approaches and may be even compare the speed.
If it's not broken, fix it until it is.
My Blog