• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Remote last 3 asterisks (***) from MySQL Field

I'm trying to figure out how to write a query that will remove the last 3 asterisks from a VARCHAR field only if they exist. I can't find much on google, any help is appreciated! Thank you!
0
brendan-amex
Asked:
brendan-amex
  • 3
1 Solution
 
Patrick MatthewsCommented:
UPDATE SomeTable
SET SomeColumn = LEFT(SomeColumn, LEN(SomeColumn) - 3)
WHERE RIGHT(SomeColumn, 3) = "***"
0
 
brendan-amexAuthor Commented:
I'm running this in MySQL (phpmyadmin to test before moving it into php) and it says "FUNCTION databasename.LEN does not exist" Is there another way to do this that will work on MySQL?
0
 
brendan-amexAuthor Commented:
nevermind, figured it out.

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

0
 
brendan-amexAuthor Commented:
Found the answer myself online.

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
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!

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