Is there a way to update a certain part of field in an SQL query? Like a replace of some kind? like a string replace? I saw this somewhere. Can’t remember.
I’m not understanding your question correctly, but I guess you can use str_replace or str_ireplace in PHP to do string replace.
Depends what you mean and what version of SQL you are using!
You can use
REPLACE (<search>, <find>, <replace>)
in MSSQL to replace fields in an update - i.e.
UPDATE products SET Description = REPLACE(Description, 'Hello', 'Bye Bye') WHERE ID = 1
Not sure about the MySQL syntax - google it or look at MySQL docs online!
I meant like doing this in the SQL. Like replacing certain data in a field, because of this, without affecting the rest of it. How would the query look?
I’m still not 100% understanding your problem -
The SQL statement I’ve posted will update 1 field in SQL (a field called Description) replacing any instances of the string ‘Hello’ with the string ‘Bye Bye’.
It’s all done in the query - no PHP or other langauages needed…
Oops! I’ll try this out. I didn’t see your post because I didn’t refresh after taking my machine off of standby.
btw: what is that syntax called there?
The whole REPLACE (<search>, <find>, <replace>) part you did just there to show what the procedure looked like ? I’ve seen that in tutorial books. Is that just a way to display classes, params, and functions? Either way, I think it’s very helpful.
Updated:
Yep. This is correct. Thank you.
That syntax is just generic old T-SQL or Transact SQL
REPLACE is just a SQL function which is available to most database implementations - this one I know works in MSSQL and I guess you are using MySQL