Update using Substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • loydbrahn
    New Member
    • Sep 2006
    • 2

    Update using Substring

    I have a SQL Table I am trying to update...I would like to add '-000' to the end of every value in a column, GLSegment.

    I can do this for one row using this statement...

    UPDATE CmpnyGLSegments
    SET GLSegment = (SELECT SUBSTRING (GLSegment, 1, 3) FROM CmpnyGLSegments WHERE RowID = 2)+'-000'
    WHERE RowID = 2

    but do not know how to do this for every row at once. I would like to take each existing GLSegment value for each row, and add '-000'.

    Thanks for any help you can provide.
  • agocurti
    New Member
    • Sep 2006
    • 6

    #2
    Originally posted by loydbrahn
    I have a SQL Table I am trying to update...I would like to add '-000' to the end of every value in a column, GLSegment.

    I can do this for one row using this statement...

    UPDATE CmpnyGLSegments
    SET GLSegment = (SELECT SUBSTRING (GLSegment, 1, 3) FROM CmpnyGLSegments WHERE RowID = 2)+'-000'
    WHERE RowID = 2

    but do not know how to do this for every row at once. I would like to take each existing GLSegment value for each row, and add '-000'.

    Thanks for any help you can provide.
    UPDATE CmpnyGLSegments
    SET GLSegment = GLSegment + '-000'

    Comment

    • loydbrahn
      New Member
      • Sep 2006
      • 2

      #3
      Thanks for the help!

      Comment

      • Kgirl
        New Member
        • Oct 2006
        • 2

        #4
        Hi!! Can I delete '-000' instead of adding ?????????
        I would like to delete '-000' at the begining of every value in a column, how can I do that???

        Comment

        • iburyak
          Recognized Expert Top Contributor
          • Nov 2006
          • 1016

          #5
          [PHP]UPDATE CmpnyGLSegments
          SET GLSegment = Replace(GLSegme nt, '-000','')[/PHP]

          Comment

          Working...