Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

Help, need phpmyadmin sql query for search & edit/delete

I need an sql query to search "wp_postmeta" table for rows with meta_key "price" and meta_value more than 1 thousand (eg 1.084.51) and delete the first dot of the meta_value.
before: 1.084.51 -> after: 1084.51
I dont know if it is possible to do this with an sql query, anyway I hope it is possible.

Here is a picture:
price

Thanks in advance, Nicolas...
0
Nicolas Lagios
Asked:
Nicolas Lagios
1 Solution
 
Walter RitzelSenior Software EngineerCommented:
the code is this:
update wp-postmeta
set meta_value = SUBSTR(CONVERT(CONVERT(REPLACE(META_VALUE,'.',''),DECIMAL(16))/100.00,CHAR),1,LENGTH(CONVERT(CONVERT(REPLACE(META_VALUE,'.',''),DECIMAL(16))/100.00,CHAR))-2)
where meta_key = 'price';

Open in new window


It could be improved a lot with regular expressions, but this way uses most basic mysql functions.
0
 
Nicolas LagiosAuthor Commented:
Actually accidentally in the first line between wp & postmeta you have add a dash instead of put an underscore.

The code is working 100%, thank you very much Walter Ritzel, appreciate for your time.

This is the code:

update wp_postmeta
set meta_value = SUBSTR(CONVERT(CONVERT(REPLACE(META_VALUE,'.',''),DECIMAL(16))/100.00,CHAR),1,LENGTH(CONVERT(CONVERT(REPLACE(META_VALUE,'.',''),DECIMAL(16))/100.00,CHAR))-2)
where meta_key = 'price';

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now