Subject Re: [firebird-support] increment
Author Svein Erling Tysvær
It is possible to do this with a complex, but straight UPDATE statement. However, my hunch is that the below is simpler:

execute block as
  declare variable i integer;
  declare variable PK <whatever>;
  i = 1;
  for select <PrimaryKey> 
      from table
      where year = 2010
      order by month, <PrimaryKey>
      into :PK do
      update table
         set "POS" = i
      where <PrimaryKey> = :PK;
      i = i + 1;


2017-06-15 15:33 GMT+02:00 'Check_Mail' check_mail@... [firebird-support] <>:

How can I increment consisting records like this:

Year  month   order         pos
2010  2                 1        null
2010  2                 1        null
2010  2                 1        null
2010  3                 2       null

Pos should be auto increment for all 2010 2 records, null to 1, the second
record null to 2 til 4

Update table set pos = coalesce(pos,0)+1 where year = 2010 and month = 2
works not, all records have the pos=1 value

Thank you

Best regards


------------------------------ ------
Posted by: "Check_Mail" <check_mail@...>
------------------------------ ------

++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++ ++++++

Visit 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 resources/documents/

++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++ ++++++
------------------------------ ------

Yahoo Groups Links

<*> To visit your group on the web, go to: firebird-support/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to: firebird-support/join
    (Yahoo! ID required)

<*> To change settings via email:

<*> To unsubscribe from this group, send an email to:

<*> Your use of Yahoo Groups is subject to: us/yahoo/utos/terms/