Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Location
    Dartmouth, NS Canada
    Posts
    2,378
    Plugin Contributions
    0

    Default A little SQL help needed

    While working on my test site I inadvertently uploaded some products with the wrong model numbers. All my model numbers should be 3 digits, even those that are less than 3 significant digits. For example, model number should be 003 rather than 3. My text file had been modified in another app that didn't keep the zeros, and I didn't notice in time.

    So now I'd like to delete all products whose model number is less than 3 digits in length. In other words, I need a little grep inside the SQL statement. Since my grep skills are about equal to my SQL skills, and neither are up to the task, I wonder if some Zen guru could help.

    TIA

    Rob

  2. #2
    Join Date
    Aug 2004
    Posts
    1,590
    Plugin Contributions
    1

    Default Re: A little SQL help needed

    Rather than deleting these fields, why not initiate a batch rename command from your phpmyadmin within the SQL query window ?

  3. #3
    Join Date
    Nov 2006
    Location
    Dartmouth, NS Canada
    Posts
    2,378
    Plugin Contributions
    0

    Default Re: A little SQL help needed

    Because the upload also included the correctly modelled products, so the ones with the wrongly formatted model number are redundant. I should have mentioned that.

    Rob

  4. #4
    Join Date
    Mar 2007
    Posts
    159
    Plugin Contributions
    0

    Default Re: A little SQL help needed

    well, I'd check to be sure first,

    run

    SELECT * FROM `YOUR PREFIX HEREproducts`
    WHERE (`products_model` REGEXP '^..$' OR
    `products_model` REGEXP '^.$');

    from my phpadmin and make sure you only get back what you want,
    this will only show stuff with 1 or 2 digit model#....assuming thats what you want
    I'm not sure how you would get the stuff out of
    products_description

    changing SELECT to DELETE will nuke them. did I say make a backup yet?
    Hm... shoulda said that first....

  5. #5
    Join Date
    Nov 2006
    Location
    Dartmouth, NS Canada
    Posts
    2,378
    Plugin Contributions
    0

    Default Re: A little SQL help needed

    Hi,

    ^.$ and ^..$

    That's the part I didn't know. Neat!

    Now if only I hadn't gotten impatient and deleted them manually. <:-)

    Rob

  6. #6
    Join Date
    Mar 2007
    Posts
    159
    Plugin Contributions
    0

    Default Re: A little SQL help needed

    Doh! Sorry about that, just found the thread when I posted.

    ^ <- beginning of word
    . <- wildcard character
    $ <- end of word


    so ^..$ is only match things 2 chars long
    ^.$ one char

    Hm, I guess you could use LIKE "__" or LIKE "_" also......
    man I rate regular expressions, they make my head hurt

 

 

Similar Threads

  1. v139h Ticket printing - nearly there. Just need a little SQL help please
    By rustwood in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 6 Jan 2014, 11:20 PM
  2. SQL JOIN (help needed)
    By stagebrace in forum General Questions
    Replies: 0
    Last Post: 17 Apr 2009, 11:26 PM
  3. A little (ok a lot) of javascript help needed please
    By 0be1 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Aug 2008, 02:16 PM
  4. A little help with a back button needed
    By red8ii8 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 13 Jun 2007, 07:24 PM

Posting Permissions

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