Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Moving a record pointer.
Message
 
 
À
10/10/2000 11:34:00
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00427244
Message ID:
00427384
Vues:
13
No. First of all, there is no explicit record pointer for SQL Server. There is a row position and a page number but these are dynamic and could change dependind on your indexes.

What you need to do is track the value of the previous value in the list and modify the select statement to only get records with values greater than or equal to the previous value. The cursor should not contain the previously processed records (rows).

Now if the value in code has a lot of duplicates, you could change the ORDER BY clause and order by code and then idkey. You could pass in both the last idkey and the code values. The SQL statement that creates the cursor could first try to gather rows with a matching code value and an idkey greater than the passed one. If you get anything, you can simply fetch the next record without doing a while. If it doesn't find a match, simply retrive all the rows with values greater than the passed in code. The first record should be the 'NEXT' record in your processing.

Just some thoughts.

>Do I understand you right that the only way to position a record pointer is then by doing a WHILE loop?
>
>>You could pass in a key to start from and add a WHERE clause that gets everything greater than or equal to the passed in ID. If you don't pass anything in, retrieve all records.
>>
>>HTH.
>>
>>>I have created the following Stored procedure:
>>>
>>>
>>>CREATE PROCEDURE [omcountry_moveto] @lcAction CHAR(10), @lcCurIdKey
>>> UNIQUEIDENTIFIER, @lcNewIdKey UNIQUEIDENTIFIER OUTPUT AS
>>>DECLARE omcountry_cursor CURSOR SCROLL FOR SELECT idkey FROM omcountry ORDER BY code
>>>OPEN omcountry_cursor
>>>IF (@lcAction = 'TOP')
>>>BEGIN
>>>	FETCH FIRST FROM omcountry_cursor INTO @lcNewIdKey
>>>END
>>>IF (@lcAction ='BOTTOM')
>>>BEGIN
>>>	FETCH LAST FROM omcountry_cursor INTO @lcNewIdKey
>>>END
>>>IF (@lcAction = 'NEXT')
>>>BEGIN
>>>	FETCH NEXT FROM omcountry_cursor INTO @lcNewIdKey
>>>END
>>>IF (@lcAction = 'PREV')
>>>BEGIN
>>>	FETCH PRIOR FROM omcountry_cursor INTO @lcNewIdKey
>>>END
>>>CLOSE omcountry_cursor
>>>DEALLOCATE omcountry_cursor
>>>
>>>The top and button part works fine. But how do I do with NEXT and PREV? I must first stand in the right position before I can do the FETCH command and how do I do that in the best way? I hope a WHILE loop with repeated FETCH NEXT is not the only way to walk...
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform