How to update database field value directly based on predicate

Posts   
 
    
jayrdub
User
Posts: 14
Joined: 02-Apr-2009
# Posted on: 02-Apr-2009 21:44:28   

I have a table that has a column called Ordinal used to keep track of display order. When an entity changes its ordinal value, the other records in the database need to have their ordinal value adjusted, either up or down depending on the situation. Is there a way through llblgen to do this (2.6 adapter .net 3.5)?

I would need generated queries to be something like these...


update MyTable set Ordinal = Ordinal + 1 where Ordinal >= @newOrdinal

update MyTable set Ordinal = Ordinal - 1 where Ordinal <= @newOrdinal and ordinal > @oldOrdinal

update MyTable set Ordinal =  Ordinal + 1 where Ordinal >= @newOrdinal and Ordinal < @oldOrdinal

update MyTable set Ordinal = Ordinal - 1 where Ordinal > @oldOrdinal

I don't think

adapter.UpdateEntitiesDirectly(newValues, filter);

will work because newValues is going to be static when I need to add or subtract from the current value of the field

I also know I can achieve this using sprocs or triggers, but I'd like to do it through llblgen if possible.

Thanks, Jeremy

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 02-Apr-2009 21:59:34   

You can do this using field expressions

Matt

jayrdub
User
Posts: 14
Joined: 02-Apr-2009
# Posted on: 03-Apr-2009 01:06:06   

Perfect, thanks a lot.