Update a column value, replacing part of a string
UPDATE urls
SET url = REPLACE(url, 'domain1.example/images/', 'domain2.example/otherfolder/')
UPDATE and REPLACE part of a string
You don't need wildcards in the REPLACE
- it just finds the string you enter for the second argument, so the following should work:
UPDATE dbo.xxx
SET Value = REPLACE(Value, '123', '')
WHERE ID <=4
If the column to replace is type text
or ntext
you need to cast it to nvarchar
UPDATE dbo.xxx
SET Value = REPLACE(CAST(Value as nVarchar(4000)), '123', '')
WHERE ID <=4
Update column, replace part of value
You could use the replace
function:
UPDATE content
SET keywords = REPLACE(keywords, 'tekst', 'text')
WHERE keywords LIKE '%tekst%'
UPDATE and REPLACE part of a existing column value with new column value
UPDATE [tablename] SET [RequestName] = REPLACE(RequestName,'Victor','Victor-ID')
Replace some parts of string and update the column in STANDARD SQL
You are overusing parentheses, so something does not match.
Use this:
SET year = REPLACE(REPLACE(REPLACE(REPLACE(year, ' ', ''), 'X', ''), 'V', ''), 'I', '')
SQL update part of string
Replace it
update blist
set serial_no = replace(serial_no, 'abcd_', 'xyz_')
where city = 'US'
and serial_no like 'abcd%'
Demo
Update and Replace a start part of string from a column
Can you try this one:
UPDATE myTable
SET myColumn = '/1/2/3/' + REVERSE(SUBSTRING(REVERSE(myColumn),0,CHARINDEX('/',REVERSE(myColumn))))
It should insert /1/2/3/
in front and keep the part after last /
from the original column value.
EDIT:
By the way, your query would also work if you removed SELECT FROM
part.
UPDATE myTable
SET myColumn = REPLACE(myColumn, SUBSTRING(myColumn, 0, len(myColumn) - CHARINDEX('/',REVERSE(myColumn)) +1), '/1/2/3')
Problem is, your query with select returned all the rows from your table and tried to update your single row value with values from subquery. That's why you got an error.
MYSQL: Update a column value from a substring in another column?
Use SUBSTRING_INDEX
:
UPDATE yourTable
SET link_Id = SUBSTRING_INDEX(Applicant, '_', -1);
Related Topics
MySQL Select Dynamic Row Values as Column Names, Another Column as Value
How to Create Multiple One to One's
Operand Should Contain 1 Column - MySQL Not In
Difference Between "Read Commited" and "Repeatable Read"
Get Record Counts For All Tables in MySQL Database
Table-Less Union Query in Ms Access (Jet/Ace)
How to Create a Sequence in MySQL
How to Get Script of SQL Server Data
MySQL: View With Subquery in the from Clause Limitation
SQL Server: Make All Upper Case to Proper Case/Title Case
Safely Rename Tables Using Serial Primary Key Columns
Sql: Between VS ≪= and ≫=
Common Table Expression, Why Semicolon
Database-Independent SQL String Concatenation in Rails
SQL Server:Dynamic Pivot Over 5 Columns
SQL Server: Howto Get Foreign Key Reference from Information_Schema