Subject | Re: [firebird-support] Sequence |
---|---|
Author | setysvar |
Post date | 2016-12-02T21:38:58Z |
Olaf wrote 02.12.2016 10:43:
SET PRIO = CASE
WHEN ID = :ID THEN :NEW_VALUE -- The ID you
explicitly want to set
WHEN PRIO < :NEW_VALUE THEN PRIO - 1 -- When
OldValue < NewValue, subtract from those that get lower priority
WHEN PRIO > :NEW_VALUE THEN PRIO + 1 -- When
OldValue > NewValue, add to those that get higher priority
WHEN :OLD_VALUE < :NEW_VALUE THEN PRIO - 1 -- The record
with the same value as NewValue should also be subtracted/added
ELSE PRIO + 1
END
WHERE PRIO BETWEEN IIF(:OLD_VALUE < :NEW_VALUE, :OLD_VALUE, :NEW_VALUE)
AND IIF(:OLD_VALUE < :NEW_VALUE, :NEW_VALUE, :OLD_VALUE)
I haven't tried the statement, and there may well be some errors (e.g.
it wouldn't surprise med if the comparison part of the IIF complained
about 'unknown type').
HTH,
Set
>Also I can do the following:without a loop?
>
>Priority in steps of 1
>
>ID 10 Prio 1
>ID 20 Prio 2
>ID 23 Prio 3
>ID 11 Prio 4
>
>Now the user can Set the ID 23 to Prio 2, how can I realize this
>UPDATE OLAF_TABLE
>Update table set prio = newprio(1) where id = 20;
>Update table set prio = prio – 1 where prio < newprio;
>Update table set prio = prio + 1 where prio > newprio;
>
>..more simplier?
SET PRIO = CASE
WHEN ID = :ID THEN :NEW_VALUE -- The ID you
explicitly want to set
WHEN PRIO < :NEW_VALUE THEN PRIO - 1 -- When
OldValue < NewValue, subtract from those that get lower priority
WHEN PRIO > :NEW_VALUE THEN PRIO + 1 -- When
OldValue > NewValue, add to those that get higher priority
WHEN :OLD_VALUE < :NEW_VALUE THEN PRIO - 1 -- The record
with the same value as NewValue should also be subtracted/added
ELSE PRIO + 1
END
WHERE PRIO BETWEEN IIF(:OLD_VALUE < :NEW_VALUE, :OLD_VALUE, :NEW_VALUE)
AND IIF(:OLD_VALUE < :NEW_VALUE, :NEW_VALUE, :OLD_VALUE)
I haven't tried the statement, and there may well be some errors (e.g.
it wouldn't surprise med if the comparison part of the IIF complained
about 'unknown type').
HTH,
Set