Olaf wrote 02.12.2016 10:43:
>Also I can do the following:
>
>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
without a loop?
>
>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?
UPDATE OLAF_TABLE
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
------------------------------------
------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu. Try FAQ and other links from the left-side menu there.
Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/firebird-support/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/