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.
| 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 TRANSACTIONUPDATE MyTableSET Position = Position + 1WHERE Position >= 7IF @@ERROR <> 0 GOTO ErrorRollbackUPDATE MyTableSET Position = 7WHERE MyPK = ... some ID value for the record being moved ...IF @@ERROR <> 0 GOTO ErrorRollbackCOMMITRETURN 0ErrorRollback:ROLLBACKRETURN 1 Kristen |
 |
|
|
|
|
|