Generate number fields

  • Hi all,

    I hope someone can help with advice. What would be the best approach to create an output for the below scenario. If I have a table with an assessment code and description and I would then like to populate every occurence of assesementcode / description with a mark system of say 1 to 10

    Thanks In advance.

    Example 1

    Attachments:
    You must be logged in to view attached files.
  • You could do something like this

    SELECT src.AssessmentCode, src.AssessmentDescriptio, m.Mark
    FROM YourSchema.YourTable AS src
    CROSS JOIN (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) AS m(Mark)
  • It's actually got a name for that type of process... "Relational Multiplication".  The code that Des Norton wrote above will absolutely do the trick.  It's also known as a "Cartesian Product" in this case.

    --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 3 posts - 1 through 3 (of 3 total)

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