Skip to main content
Participant
June 26, 2008
Question

Handling Strings?

  • June 26, 2008
  • 1 reply
  • 194 views
I'm currently working with a database, in which some primary keys are varchars. I'm supposed to make an application that creates an "automatic" primary key for each new register, currently for instance, if the max(pk) is 100, the new one is 101. My question is, how to handle strings in a way in which if max(pk) is abx, I can do abx +1 to get aby - or similar. Any comments?
    This topic has been closed for replies.

    1 reply

    June 27, 2008
    Here is how I might approach the problem:

    1. See if the last set of values are numbers using a Regular Expression to look at the end of the string for numbers
    2 If so, strip out those numbers into a variable and the characters into a second variable
    2.1 Add 1 to the variable.
    2.2. Join the second variable with new first variable to get your new number
    3. If there are no numbers at the end, then append 1 to the end.