Quickly adding text to a mysql text field that is NOT empty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    Quickly adding text to a mysql text field that is NOT empty

    Hi all

    Is there a way to insert text into a mysql text field that already has
    text into it; without having first to extract the existing data and
    append the new text to that string variable and then insert the new
    string.

    Basically i'm looking for a way to do it with a single query not 2 (one
    being a select to gather existing data).

    Please help!

  • xclarky@gmail.com

    #2
    Re: Quickly adding text to a mysql text field that is NOT empty

    I could have sworn I already replied to this but it appears that it did
    not go through, but anyway; you want to modify the contents of an
    existing field without having to fetch it using a query, yes? This is
    possible through the use of MySQL's CONCAT() function:

    UPDATE `my_table` SET `my_field` = CONACT(`my_fiel d`, ' append this');

    So, for example the value of 'my_field' is 'John'. Upon running the
    query the value of 'my_field' will become 'John append this'. Hope that
    helps.

    Comment

    • xclarky@gmail.com

      #3
      Re: Quickly adding text to a mysql text field that is NOT empty

      So basically you want to append a string or data to existing data in a
      field without having to fetch the contents of that field first? Yeah,
      that's possible:

      UPDATE `my_table` SET `myfield` = CONCAT(`myfield `, 'newvalue');

      So say the value of 'myfield' was 'John' and I ran that query, the
      value of 'myfield would now be 'Johnnewvalue'. Is that what you wanted?

      Comment

      • monomaniac21

        #4
        Re: Quickly adding text to a mysql text field that is NOT empty

        [color=blue]
        > So say the value of 'myfield' was 'John' and I ran that query, the
        > value of 'myfield would now be 'Johnnewvalue'. Is that what you wanted?[/color]

        Thanks for your help xcla, the problem I have is that I don't know what
        is in the first part of the string, so i need a query which adds to the
        data that is in there without me defining it.

        Comment

        • monomaniac21

          #5
          Re: Quickly adding text to a mysql text field that is NOT empty

          Yeah I've got it working now thanks!

          Comment

          • xclarky@gmail.com

            #6
            Re: Quickly adding text to a mysql text field that is NOT empty

            You're very welcome, I used 'John' as an example, just specifying the
            field name works as I assume you've already found out. Glad I could
            help!

            Comment

            • Jim Michaels

              #7
              Re: Quickly adding text to a mysql text field that is NOT empty


              <xclarky@gmail. com> wrote in message
              news:1139149880 .794194.28780@o 13g2000cwo.goog legroups.com...[color=blue]
              >I could have sworn I already replied to this but it appears that it did
              > not go through, but anyway; you want to modify the contents of an
              > existing field without having to fetch it using a query, yes? This is
              > possible through the use of MySQL's CONCAT() function:
              >
              > UPDATE `my_table` SET `my_field` = CONACT(`my_fiel d`, ' append this');[/color]

              you mean CONCAT
              [color=blue]
              >
              > So, for example the value of 'my_field' is 'John'. Upon running the
              > query the value of 'my_field' will become 'John append this'. Hope that
              > helps.
              >[/color]


              Comment

              Working...