Is it possible to generate unique values for a field where the uniqueness is determined by more than one field?

For instance, I am generating sales receipts and the ticket number (integer) can't repeat when two fields coincide. The fields are ShopNumber (integer) and TillNumber (integer), so there should be no repeats for the combination ShopNumber+TillNumber+TicketNumber.

Is this possible?

Thanks,
Martin.
MartinH
0

Comments

4 comments

  • peter.peart
    Thanks for your post. Unfortunately, It's not possible to have data generated based on relationships between columns (unless it's PK > FK).

    I suppose in this instance, if the value of the integer isn't important, you could use a RegEx for each column that specified a value between certain values that was different for all columns, i.e:

    ShopNumber = 1 - 2000
    TillNumber = 2001 - 4000
    TicketNumber = 4001 - 6000

    Or something along those lines.

    HTH!

    Pete
    peter.peart
    0
  • MartinH
    Peter:

    If this is not available off-the-shelf, could I do it with a custom generator?

    If this is (in theory) possible, I will look into writing one.

    Thanks,
    Martin.
    MartinH
    0
  • peter.peart
    Hi Martin,

    It should be possible. There's an article on our Simple Talk website which explains how to do this in more detail:

    http://www.simple-talk.com/dotnet/.net- ... generator/

    HTH!

    Pete
    peter.peart
    0
  • MartinH
    Peter:

    Yes, that will work fine. I'll write my own generator to support this scenario,

    Thanks for the help.

    Regards,
    Martin.
    MartinH
    0

Add comment

Please sign in to leave a comment.