Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. alphanumeric number generation

alphanumeric number generation

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AMRITESH ASTHANA
    wrote on last edited by
    #1

    I am developing a project ASSET MANAGEMENT SYSTEM in which i am giving the asset Id to every asset . I have my office at different places in INDIA. Every now and then new asset is purchased so I want a perfect record in a database. My question is that i want a asset number consists of company name then 3 words of city and then number . for eg: let company name is XYZ it is purchased in city MUMBAI so i want asset id like----> XYZ/MUM/001. on every new entry of a record. AMRITESH ASTHANA

    L G 2 Replies Last reply
    0
    • A AMRITESH ASTHANA

      I am developing a project ASSET MANAGEMENT SYSTEM in which i am giving the asset Id to every asset . I have my office at different places in INDIA. Every now and then new asset is purchased so I want a perfect record in a database. My question is that i want a asset number consists of company name then 3 words of city and then number . for eg: let company name is XYZ it is purchased in city MUMBAI so i want asset id like----> XYZ/MUM/001. on every new entry of a record. AMRITESH ASTHANA

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are talking about a real-life identifier. That's not the same as a primary key in a database. A primary key does NEVER, EVER have a constant text in there. You create a field for you numeric; don't use the PK. Next, add in a FK to the place where it is bought. Then create a calculated field to get the name of the place, and format it as your real-life identifier.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      • A AMRITESH ASTHANA

        I am developing a project ASSET MANAGEMENT SYSTEM in which i am giving the asset Id to every asset . I have my office at different places in INDIA. Every now and then new asset is purchased so I want a perfect record in a database. My question is that i want a asset number consists of company name then 3 words of city and then number . for eg: let company name is XYZ it is purchased in city MUMBAI so i want asset id like----> XYZ/MUM/001. on every new entry of a record. AMRITESH ASTHANA

        G Offline
        G Offline
        George Jonsson
        wrote on last edited by
        #3

        You could have three columns in your table called company_name of type varchar(5) (or whatever length you desire) purchase_city of type varchar(5) (or whatever length you desire) asset_sn of type int Make these columns unique so you can't add the same number twice. Index name could be ix_asset_number When you add a new inventory item you first get the last registered row for the company and city. SELECT LAST(asset_sn) AS AssetNumber FROM assets WHERE company_name = 'XYZ' AND purchase_city = 'MUM'; Then increment the AssetNumber with 1 and insert the new record.

        A 1 Reply Last reply
        0
        • G George Jonsson

          You could have three columns in your table called company_name of type varchar(5) (or whatever length you desire) purchase_city of type varchar(5) (or whatever length you desire) asset_sn of type int Make these columns unique so you can't add the same number twice. Index name could be ix_asset_number When you add a new inventory item you first get the last registered row for the company and city. SELECT LAST(asset_sn) AS AssetNumber FROM assets WHERE company_name = 'XYZ' AND purchase_city = 'MUM'; Then increment the AssetNumber with 1 and insert the new record.

          A Offline
          A Offline
          AMRITESH ASTHANA
          wrote on last edited by
          #4

          Thanks George it works :)

          G 1 Reply Last reply
          0
          • A AMRITESH ASTHANA

            Thanks George it works :)

            G Offline
            G Offline
            George Jonsson
            wrote on last edited by
            #5

            You are welcome.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups