SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast RequiemShark's Avatar
    Join Date
    Mar 2002
    Location
    Atlanta, GA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Copying values from one field to another

    I have a Products table that has a 'products_image' field. I want to copy the current values in 'products_image' to 'products_bigimage' and modify the current value in 'products_image' to have a "tn_" prefix.


    Currently:

    product_image
    -------------
    FerF150.jpg


    Desired:

    product_image product_bigimage
    ------------- ----------------
    tn_FerF150.jpg FerF150.jpg



    There has to be SQL script that I can run to do this for the current 500+ products. Instead of editing each record individually.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    update products
    set products_bigimage
    = products_image
    , products_image
    = concat('tn_',products_image)

    caution: untested

    you may want to do it in two passes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may want to check length(product_image) before doing the concat()

    Let's say the field length is 10 (just an example!) and one image is called 'image.jpg', then concat('tn_', product_name) => 'tn_image.j'

  4. #4
    SitePoint Enthusiast RequiemShark's Avatar
    Join Date
    Mar 2002
    Location
    Atlanta, GA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks R397!
    I appreciate the warning Jofa, luckily the field is varchar(64).


Bookmarks

Posting Permissions

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