ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

HELP: Generating sequence #

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HELP: Generating sequence #

    I need a way to create a sequence number using SQL. I have a table that contains about 4000 entries. There is a colum called ARSEQ# that is currently set to zero (0). I would like to create an SQL statement to populate the SEQ column.

    These are the steps I have taken so far:

    /* clear the sequence # */
    update arfile
    set ARSEQ# = 0

    Then I would like to update the sequence number:

    update arfile
    set ARSEQ# = <something that will generate a number>

    Anyone know how I can do this without having to create an RPG program?

  • #2
    Re: HELP: Generating sequence #

    I went ahead and just wrote a program. Thanks.

    Comment


    • #3
      Re: HELP: Generating sequence #

      I would have done the same

      jamie
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: HELP: Generating sequence #

        Hi,

        if you are on release V5R3 or higher it is possible to create a sequence object, and use it to update your file:

        PHP Code:
        CREATE SEQUENCE MySchema/MySequence 
            
        AS INTEGER 
            START WITH 1 
            INCREMENT BY 1 
            MINVALUE 1 
            MAXVALUE 2147483647 
            NO CYCLE CACHE 20 ORDER 


        update MyTable
            set Counter 
        Next value for MySequence
        Birgitta

        Comment


        • #5
          Re: HELP: Generating sequence #

          Thanks birgitta, I tried on my own to do this and was lost......

          Take care
          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment

          Working...
          X