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. Replace Text

Replace Text

Scheduled Pinned Locked Moved Database
help
4 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
    Mohammed Elkholy
    wrote on last edited by
    #1

    hi , first i would thank you for help i have a column in table contains a code for students the code format is 11-1-07-0001 what i want , i want to replace the first tow digits from 11 to 01 without any efection to the other characters

    MD_NADA

    S S 2 Replies Last reply
    0
    • M Mohammed Elkholy

      hi , first i would thank you for help i have a column in table contains a code for students the code format is 11-1-07-0001 what i want , i want to replace the first tow digits from 11 to 01 without any efection to the other characters

      MD_NADA

      S Offline
      S Offline
      Shpendh
      wrote on last edited by
      #2

      did you try it with SUBSTRING?

      spaps

      1 Reply Last reply
      0
      • M Mohammed Elkholy

        hi , first i would thank you for help i have a column in table contains a code for students the code format is 11-1-07-0001 what i want , i want to replace the first tow digits from 11 to 01 without any efection to the other characters

        MD_NADA

        S Offline
        S Offline
        Support123
        wrote on last edited by
        #3

        This is not something that happens to me every day... for once i can finally give help to someone else and not be the one asking the question :) SELECT YourStudentNumberColumn AS [Test], '01' + SUBSTRING(YourStudentNumberColumn,3,LEN(YourStudentNumber) - 2) AS [TestAfterUpdate] Notice the 3 in the substring, this is the start position. The LEN(YourStudentNumber) - 2 is the amount of character to use. So it will start at position 3 being the first '-' in your student number and end at the end of the student number as it gets the length of the YourStudentNumber subtracts 2 as you start at position 3 (the first '-'). If this is unclear run the query in sql and change the '- 2' to '- 3' and you will see what it does. the SUBSTRING works like this. Substring(YourValue, StartPosition(1 for beginning of your value), AmountOfCharacters) I added the select statement so that you can make sure that this is the correct value that you need. If it is... you can run it like this for the UPDATE: UPDATE YourTableName SET YourStudentNumberColumnName = '01' + SUBSTRING(YourStudentNumberColumnName,3,LEN(YourStudentNumber) - 2)

        "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

        M 1 Reply Last reply
        0
        • S Support123

          This is not something that happens to me every day... for once i can finally give help to someone else and not be the one asking the question :) SELECT YourStudentNumberColumn AS [Test], '01' + SUBSTRING(YourStudentNumberColumn,3,LEN(YourStudentNumber) - 2) AS [TestAfterUpdate] Notice the 3 in the substring, this is the start position. The LEN(YourStudentNumber) - 2 is the amount of character to use. So it will start at position 3 being the first '-' in your student number and end at the end of the student number as it gets the length of the YourStudentNumber subtracts 2 as you start at position 3 (the first '-'). If this is unclear run the query in sql and change the '- 2' to '- 3' and you will see what it does. the SUBSTRING works like this. Substring(YourValue, StartPosition(1 for beginning of your value), AmountOfCharacters) I added the select statement so that you can make sure that this is the correct value that you need. If it is... you can run it like this for the UPDATE: UPDATE YourTableName SET YourStudentNumberColumnName = '01' + SUBSTRING(YourStudentNumberColumnName,3,LEN(YourStudentNumber) - 2)

          "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

          M Offline
          M Offline
          Mohammed Elkholy
          wrote on last edited by
          #4

          thank you very much , this is what i want i dont have any words to say but i am thankfull for any one in the world liks to help the others

          MD_NADA

          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