Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    116

    Unanswered: Concatenating 2fields when doing update

    How do i concatenate "S_" with data in field2 and straight away update field2 to the new string

    For an example, one of the data in field2 is Mouse...How to write an update query so that all the data 'Mouse' in field2 is replace by S_Mouse ?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    PHP Code:
    update table_name
    set columnA 
    'S_'||columnA
    where columnA 
    'Mouse'
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Feb 2005
    Posts
    116
    Lets say i dont know whats the value of columnA, and i just want to concatenate all data in ColumnA to U_ColumnA, how do i do that

    Quote Originally Posted by The_Duck
    PHP Code:
    update table_name
    set columnA 
    'S_'||columnA
    where columnA 
    'Mouse'

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    And what is "U_ColumnA"? Another field in your table? If so, my lucky guess would be this: remove WHERE clause from Duck's query and substitute columnA with U_ColumnA on the left side of the equation sign.

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    An update without a where does every record. The following would update all records.

    update table_name
    set columnA = 'U_'||columnA;


    The following would only update those records which had information in ColumnA.

    update table_name
    set columnA = 'U_'||columnA
    where columnA is not null;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •