Incremental Column Population

  • I have a table like below

    Table1

    Col1    col2    col3

    RA1    NULL    NULL

    RA2    NULL    NULL

    RA3    NULL    NULL

    Col2 and Col3 are Null NOW. Col2 needs to be populated as BON001 to BON004000. Fix prefix BON00+ One number(From 1 to 4000 each) for each records.  Similarly Col3 should have RBO001 to RBO4000. Thus table records looks like this.

    Col1    col2      col3

    RA1    BON001   RBO001 

    RA2    BON002    RBO002

     .......   ......      ........

    RA3    BNO004000      RBO4000

     

    Could anybody please provide me the script how we can achieve above.

    Thanks a lot

     

     

     

  • Hello,

    just a few questions before we can start thinking about a solution...

    How do we know which row should get which number (of the 1 - 4000)? Or is it OK to fill the numbers in any order? Since you are showing the row with 'RA3' in Col1 having BNO004000, we have no clue as to the ordering.

    Also, what about the format of Col2? Is it OK that first row has the number part 001, while the last has 004000, or is that a mistake? I would suppose some leading zeroes to the smaller numbers (like 000001), so that all the numbers are equally long - otherwise you have no chance to order by that column. Column 3 is even worse that that, because it seems to compensate a bit for the length, but not fully... adds only 2 leading zeroes instead of at least 3.

  • write the script first, then post if you get problems. your requirement is very vague


    Everything you can imagine is real.

  • How in the heck does RA3 equate to an RBO of 4000???  And, what is the primary key of the table?  We need some more info on this one, for sure.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply