Please help me with below mentioned scenario->
I wanna use while loop to fetch records between 500 to 100 from among 20000 records of a particular table.
Please suggest whether by which means of looping , I will get better performance. loop handled in Page or in database procedure.
data is ->
like wise I have 20000 records and now I wanna fetch aroun 500 to 1000 records randomly and then out of these fetched records i needs to compare every row with its next row and return maximum salary row
So for these comparison purpose I was in a fix whether should i fetch the record into dataset into ASP.NET C# then should I handle it in ASP Page or shoule I handle it in Database level.Which one is better as far as performance gain is concerned.
It will be great if i get the logic for the same.
Hope this time I have clarified my query to u.
It appears that all you need is the select statement which tiles the records you return by 2 in the group and then from every such group you need to select the one of the two which has the higher salary. In this case, no fancy looping is required and all you really need is tile your records first and then number the records partitioned by the tile and ordered by salary descending. In this case, you will always get one record from every pair. In case if there is a pair where both records have the same salary then you will still get one record (probably the one which comes first on the per table's clustered index). Here is the script:
Based on the sample data in the question, the query above returns the following results:
Hope this helps,