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. Transaction to update multipel values in a table

Transaction to update multipel values in a table

Scheduled Pinned Locked Moved Database
databasequestionannouncement
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.
  • D Offline
    D Offline
    diePopster
    wrote on last edited by
    #1

    Hi There, I don't really use sql so this can be an stupid questoin but, say ive got a column called accountNumber with the following values: 55123 55124 55124 ...etc and i want to change all the values (5000+ entries) to a concatenation of '000' + the current accountNumber. i.e. 00055123;00055124;00055125 how will i achieve this? Regards and thanks

    B P 2 Replies Last reply
    0
    • D diePopster

      Hi There, I don't really use sql so this can be an stupid questoin but, say ive got a column called accountNumber with the following values: 55123 55124 55124 ...etc and i want to change all the values (5000+ entries) to a concatenation of '000' + the current accountNumber. i.e. 00055123;00055124;00055125 how will i achieve this? Regards and thanks

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      here it is

      update tablename set accountNumber = '000'+accountNumber


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      1 Reply Last reply
      0
      • D diePopster

        Hi There, I don't really use sql so this can be an stupid questoin but, say ive got a column called accountNumber with the following values: 55123 55124 55124 ...etc and i want to change all the values (5000+ entries) to a concatenation of '000' + the current accountNumber. i.e. 00055123;00055124;00055125 how will i achieve this? Regards and thanks

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        What data type is accountNumber stored in? What database are you using?

        I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        D 1 Reply Last reply
        0
        • P Pete OHanlon

          What data type is accountNumber stored in? What database are you using?

          I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          D Offline
          D Offline
          diePopster
          wrote on last edited by
          #4

          Data type is string and it is a sql express database. Also, i cannot update the etries that already have a '000' prefix so i can do something like :

          UPDATE TableName
          SET AccountNumber = '000' + AccountNumber
          WHERE AccountNumber NOT LIKE '000%'

          Correct?

          P 1 Reply Last reply
          0
          • D diePopster

            Data type is string and it is a sql express database. Also, i cannot update the etries that already have a '000' prefix so i can do something like :

            UPDATE TableName
            SET AccountNumber = '000' + AccountNumber
            WHERE AccountNumber NOT LIKE '000%'

            Correct?

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            What you need to do is use the LPAD function in SQL Server to pad the number to a set size. So, suppose you want to have it padded out to 10 characters, you'd use

            UPDATE TableName SET AccountNumber = LPAD(AccountNumber, 10, '0')

            I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            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