• ChrisM@Work (9/5/2014)


    Eirikur Eiriksson (9/5/2014)


    ChrisM@Work (9/5/2014)


    Meatloaf (9/3/2014)


    Hello,

    I trying to figure out the logic to add a number to the end of an ID to create a series.

    For example, I have an EventID that may have many sub events.

    If the EventID is 31206, and I want to have subEvents, I would like have the following sequence. In this case, lets say I have 4 sub Events so I want to check the EventID and then produce:

    312061

    312062

    312063

    312064

    How can I check what the EventID is, then concatenate a sequence number by the EventID?

    If you pursue this, you will destroy your EventID key. Matching to EventID in any other table will require that you identify which part of EventID is the EventID and which part is the subeventid. If you want to have a subeventid somewhere then create a new column for it. Having said that, creating sequences and subsequences using ROW_NUMBER() is so trivially easy that perhaps you should be evaluating subeventid in code.

    Chances are that this serialization is being used outside the scope of the database, ie. enumeration of report or invoice items, who knows?

    😎

    Nobody, Mr Viking - but it wasn't explicit from earlier posts in this thread that if it is within the scope of the db, there are easy ways of getting the same functionality without the penalties the OP would experience with the original proposal.

    I'm not by any means trying to rape or pillage the forum's high quality of advice, only pointing out that there could be other usage than assumed. Maybe a simple ERD could help explaining the relational solution

    😎

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

    | Event | | SubEvent |

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

    | EventId |-|--, | SubEventId |

    | (details)| '---o-<| EventId |

    +----------+ | (details) |

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