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. Web Development
  3. ASP.NET
  4. Generating autonumber with date format like 23/Mar/2008/001 when the new record is inserted

Generating autonumber with date format like 23/Mar/2008/001 when the new record is inserted

Scheduled Pinned Locked Moved ASP.NET
sales
6 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.
  • M Offline
    M Offline
    mcmilan
    wrote on last edited by
    #1

    Hi, I am developing a web application in which the customer/user register(enter)with their complaints. When the End user enters all the required data and clicks the Register button automatically a unique number should be generated. For instance the number should be in the format like 23/Mar/2008/001 and for every new user the number should be incremented if according to the system date. If the system date changes then the number should be start again from current date/001........ Thank you Dsr

    A A 2 Replies Last reply
    0
    • M mcmilan

      Hi, I am developing a web application in which the customer/user register(enter)with their complaints. When the End user enters all the required data and clicks the Register button automatically a unique number should be generated. For instance the number should be in the format like 23/Mar/2008/001 and for every new user the number should be incremented if according to the system date. If the system date changes then the number should be start again from current date/001........ Thank you Dsr

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      So what do you want to know? How to do it? Where, in a database or in the web app? Please try to help yourself by being specific with what you want - nobody else knows what you are working on

      Bob Ashfield Consultants Ltd

      M 1 Reply Last reply
      0
      • M mcmilan

        Hi, I am developing a web application in which the customer/user register(enter)with their complaints. When the End user enters all the required data and clicks the Register button automatically a unique number should be generated. For instance the number should be in the format like 23/Mar/2008/001 and for every new user the number should be incremented if according to the system date. If the system date changes then the number should be start again from current date/001........ Thank you Dsr

        A Offline
        A Offline
        Arindam Tewary
        wrote on last edited by
        #3

        Hi Mcmilan, You can have a logic like this .. try it out .. could be helpful, Before that following code part gives

        --SQL SERVER 2005 code assuming that this ID will be generated at the time of insertion of values into DB

        declare @currDate varchar(20),
        @NextID varchar(20)
        select @currDate = replace(convert(varchar,getdate(),106),' ','/')
        print @currDate -- PRINTS 23/Jun/2008 FOR TODAY !!

        Pseudocode .......................................... set @CurrentDate = select replace(convert(varchar,getdate(),106),' ','/') select @MaxuserID = Max(UserIDColumn) from UserTable -- Consideing your table name is "UserTable" and Column name is "UserIDColumn" if(@CurrentDate is a SUBSTRING of @MaxuserID) { get @dateExcludedIndexPart from @MaxuserID -- here you should get 001 from "23/Mar/2008/001" @dateExcludedIndexPart++ @NextID = @CurrentDate + @dateExcludedIndexPart } else { @NextID = @CurrentDate + '001' -- First ID value of the day .. } I know there could be more better algo for your requirement !!! But you can give a try ...

        Thanks, Arindam D Tewary

        M 1 Reply Last reply
        0
        • A Ashfield

          So what do you want to know? How to do it? Where, in a database or in the web app? Please try to help yourself by being specific with what you want - nobody else knows what you are working on

          Bob Ashfield Consultants Ltd

          M Offline
          M Offline
          mcmilan
          wrote on last edited by
          #4

          I want, how to do it? And in the database.

          1 Reply Last reply
          0
          • A Arindam Tewary

            Hi Mcmilan, You can have a logic like this .. try it out .. could be helpful, Before that following code part gives

            --SQL SERVER 2005 code assuming that this ID will be generated at the time of insertion of values into DB

            declare @currDate varchar(20),
            @NextID varchar(20)
            select @currDate = replace(convert(varchar,getdate(),106),' ','/')
            print @currDate -- PRINTS 23/Jun/2008 FOR TODAY !!

            Pseudocode .......................................... set @CurrentDate = select replace(convert(varchar,getdate(),106),' ','/') select @MaxuserID = Max(UserIDColumn) from UserTable -- Consideing your table name is "UserTable" and Column name is "UserIDColumn" if(@CurrentDate is a SUBSTRING of @MaxuserID) { get @dateExcludedIndexPart from @MaxuserID -- here you should get 001 from "23/Mar/2008/001" @dateExcludedIndexPart++ @NextID = @CurrentDate + @dateExcludedIndexPart } else { @NextID = @CurrentDate + '001' -- First ID value of the day .. } I know there could be more better algo for your requirement !!! But you can give a try ...

            Thanks, Arindam D Tewary

            M Offline
            M Offline
            mcmilan
            wrote on last edited by
            #5

            Thank you Arindam D Tewary, I have one more doubt ,...where should I write the code? In stored procedure or in aspx.cs page............ Please help me in this... Thank you Mcmilan

            A 1 Reply Last reply
            0
            • M mcmilan

              Thank you Arindam D Tewary, I have one more doubt ,...where should I write the code? In stored procedure or in aspx.cs page............ Please help me in this... Thank you Mcmilan

              A Offline
              A Offline
              Arindam Tewary
              wrote on last edited by
              #6

              It should be in SQL server!! I have already mentioned that in reply ...

              Thanks, Arindam D Tewary

              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