Results 1 to 2 of 2

Thread: Auto Calculating codes using specified algorithm.

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Auto Calculating codes using specified algorithm.

    Bit of a though request from boss, and did not want to say "Dunno how"

    Each time a new product are added I must assign it a product code, which will be a 3 digit numerical code.
    For the first 9 products it should be "010" to "090".
    After that it should be "110" to "190", then "210" to "290", etc.

    Anyone did sth like this. Bit late for me to think straight.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Auto Calculating codes using specified algorithm.

    So basically you just want a sequential code in multiples of 10, correct? If the data is being stored in a database then you could simply use an auto-generated ID as normal and then add an extra calculated field using an expression that multiplies the ID by 10. In SQL Server that would mean a ProductID column with (Is Identity) set to Yes and a ProductCode column with (Formula) set to 'ProductID * 10'.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width