Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 MoveUP procedure for tree

Author  Topic 

CoTuDo
Starting Member

3 Posts

Posted - 2006-05-11 : 10:32:14
My tree is built with table :
tree(treeNodeId,parentNodeId,sortOrder)
the third column: sortOrder it's for sort the tree, to have the possibility to move up and down...but i still can't realize it...please help me...:)

Kristen
Test

22859 Posts

Posted - 2006-05-11 : 11:03:51
If you want to move the current node to, say, position 7 then anything currently with Position >= 7 needs to have 1 added. Probably something like:

BEGIN TRANSACTION
UPDATE MyTable
SET Position = Position + 1
WHERE Position >= 7
IF @@ERROR <> 0 GOTO ErrorRollback

UPDATE MyTable
SET Position = 7
WHERE MyPK = ... some ID value for the record being moved ...
IF @@ERROR <> 0 GOTO ErrorRollback
COMMIT
RETURN 0

ErrorRollback:
ROLLBACK
RETURN 1

Kristen
Go to Top of Page
   

- Advertisement -