Appending data to an existing record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srkartes
    New Member
    • Sep 2006
    • 4

    #1

    Appending data to an existing record

    I am a novice when it comes to using SQL. I would like to append text to existing data in a specified column, but I can not figure out how to do it. I was trying to use an update query, but as far as I can tell this only replaces the data within the column. Any help would be appreciated
  • somaskarthic
    New Member
    • Aug 2006
    • 60

    #2
    Hi

    Use update statement .
    eg.

    table1 (tablename)
    id values
    1 text1
    2 text2
    3 text3

    Let the table1 contains two fields id and value. U need to append some text
    to the existing values. is it ?
    ok...use the following postgresql query .
    update table1 set values = values || 'newtext' where id = 1

    || ------> string concat operator

    This will result in

    table1
    id values
    1 text1newtext
    2 text2
    3 text3

    If you want to update all the rows remove the 'where' condition
    Try this and reply

    -somaskarthic






    Originally posted by srkartes
    I am a novice when it comes to using SQL. I would like to append text to existing data in a specified column, but I can not figure out how to do it. I was trying to use an update query, but as far as I can tell this only replaces the data within the column. Any help would be appreciated

    Comment

    • somaskarthic
      New Member
      • Aug 2006
      • 60

      #3
      Hi

      Here i mentioned is postgresql query , if u use some other database
      please find the appropriate sting concat operator . In postgres || is the concat operator . If you use mysql or sql server , please find the correct concatenation operator.

      -somaskarthic

      Originally posted by somaskarthic
      Hi

      Use update statement .
      eg.

      table1 (tablename)
      id values
      1 text1
      2 text2
      3 text3

      Let the table1 contains two fields id and value. U need to append some text
      to the existing values. is it ?
      ok...use the following postgresql query .
      update table1 set values = values || 'newtext' where id = 1

      || ------> string concat operator

      This will result in

      table1
      id values
      1 text1newtext
      2 text2
      3 text3

      If you want to update all the rows remove the 'where' condition
      Try this and reply

      -somaskarthic

      Comment

      • agocurti
        New Member
        • Sep 2006
        • 6

        #4
        Originally posted by somaskarthic
        Hi

        Here i mentioned is postgresql query , if u use some other database
        please find the appropriate sting concat operator . In postgres || is the concat operator . If you use mysql or sql server , please find the correct concatenation operator.

        -somaskarthic
        This is the way:

        update table1 set values = values + 'newtext' where id = 1

        Comment

        • srkartes
          New Member
          • Sep 2006
          • 4

          #5
          Thanks guys! Worked perfectly.

          Comment

          Working...