I have data with 6 characters like 123456 in a mysql database. I want to change the existing data like 123,456 . Is there any mysql query can do this. Because i want to change over 3000 records.
Try this, it will FORMAT your numbers regardless of the number of digits:
UPDATE yourtable
SET yourfield = FORMAT(yourfield,0)
Try this :
UPDATE yourtable
SET yourfield = LEFT(yourfield,3) + ',' + RIGHT(yourfield,3)
it will do what you asked for. Note it won't help if your field is not 6 characters long
update mytable set
mycolumn = replace(mycolumn, ',', '')
Related
my raw query look something like this-
UPDATE main,category,sub_category
SET main.biz_keyword = (category.category','sub_category.sub_cat_name','main.biz_keyword)
so the result something like main.biz_keyword='Doctor,General Physician,Physician'
I know this is wrong query but you got the Idea what I am looking for,
So my question is that I can do this by single query?
You might want to have a look at using CONCAT_WS(separator,str1,str2,...)
CONCAT_WS() stands for Concatenate With Separator and is a special
form of CONCAT(). The first argument is the separator for the rest of
the arguments. The separator is added between the strings to be
concatenated.
is this something you want to achieve?
Update TableName
set biz_keyword = category.category + ',' + sub_category.sub_cat_name + ',' + main.biz_keyword
Maybe you're looking for something like this?
UPDATE
main
SET
biz_keyword = CONCAT_WS(', ',
(SELECT category FROM category WHERE ... ),
(SELECT sub_cat_name FROM sub_category WHERE ... ),
biz_keyword)
Lets say that you have the following stored in table:
{2:22}{4:5}{34:4}
I what to delete {4:5} from this string but the system dosent know what the number after the ":" is just the first one. The query looks something like this:
UPDATE tbl SET this = REPLACE(this,'{4:??}','') WHERE id = 1;
What do i need to put in ?? place to return the following result?
{2:22}{34:4}
Here's one way to do it using LEFT, SUBSTRING, LOCATE and REPLACE:
update yourtable
set yourcolumn =
replace(yourcolumn,
Left(
Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)),
Locate('}',Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)))),
'')
SQL Fiddle Demo
I'm trying to do this in mysql . How can I replace parts of a string in a column in MYSQL with 1000 records. Change all records form .JPG to .gif
eg. DC3444.JPG to DC3444.gif
update your_table
set some_column = replace(some_column, '.JPG', '.gif')
UPDATE table1 SET col1 = REPLACE(col1, '.JPG','.gif')
Use this as reference : http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace
I want to update all the values in a table by trimming all the leading and trailing spaces. I have tried the following queries but neither worked.
I know that it is possible to use TRIM with SELECT, but how can I use it with UPDATE?
UPDATES teams SET name = TRIM(name)
UPDATES teams SET name = TRIM(LEADING ' ' TRAILING ' ' FROM name)
You do not have to SELECT.
Try this -
UPDATE teams SET name = TRIM(name)
WHERE 1 = 1;
UPDATE teams SET name = TRIM(name)
That should work, it is semantically correct for MySQL.
If field contain new line character then
UPDATE Tablename SET colname= TRIM(TRAILING '\r' FROM colname)
This one solves a weird problem I was having when the TRIM option does not work:
UPDATE
teams
SET
name = TRIM(BOTH UNHEX('C2A0') FROM name)
Imagine that you have a column with a bunch of fields like this:
ab
abc
abcd
...
I would like to transform these fields using a single query to something like this:
a_b
ab_c
abc_d
...
That is, inserting an underscore just before the last letter.
I could do it in a one by one basis:
update test set name = 'a_b' where name ='ab';
update test set name = 'ab_c' where name ='abc';
update test set name = 'abc_d' where name ='abcd';
But being a high number of fields to update, I figure there must be a better way to do this.
Try this query -
UPDATE test SET name = INSERT(name, LENGTH(name), 0, '_');
Use some of the string manipulation functions, something like:
SET fieldname = CONCAT(LEFT(fieldname, LENGTH(fieldname)-1),"_",RIGHT(fieldname,1))
You could use the SUBSTRING AND LENGTH functions:
UPDATE test
SET name = SUBSTRING(name, 0, LENGTH(name) - 1) + '_' + SUBSTRING(name, -1)