|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Upate based on multiple WHERE clausesenough to be dangerous! I'm storing heirarchical data in a table using preorder tree logic. Whenever I add a new node to the tree, I need to update the left and/or right values of some of the other nodes to reflect the new insertion. The way I do it now is (after I find the left value where I want to insert the node) perform two SQL commands, something like this: UPDATE myTreeTable SET nodeLeft = (nodeLeft + 2) WHERE nodeLeft >= SOMEVALUE Then I would run something like this next: UPDATE myTreeTable SET nodeRight = (nodeRight + 2) WHERE nodeRight >= SOMEVALUE This opens a "hole" where I can then insert my node. However, I would like to consolidate these into one statement, if possible. Something like: UPDATE myTreeTable SET nodeLeft = (nodeLeft + 2) WHERE nodeLeft >= SOMEVALUE, SET nodeRight = (nodeRight + 2) WHERE nodeRight >= SOMEVALUE Is this even possible via a single SQL command? I've tried every permutation I can think of in QueryAnalyzer, and nothing works. I've searched for something similar, but keep coming up empty. Thanks; Brad |
|||||||||||||||||||||||