Update Query to remove text in field

Posted on 2013-09-11
Medium Priority
Last Modified: 2013-09-11
I have a field in a table that I want to do a mass update and remove an "*" from the text.

Like the field has:


and I want to do an update and remove the asterisk so that the fields are now:

Question by:Starr Duskk
  • 3
LVL 66

Expert Comment

by:Jim Horn
ID: 39484099
The below code is a demo of how to remove all *'s.  Copy-paste it into your SSMS, execute it to verify it works, then modify to meet your needs.

Also let me know if you only want to remove the * if it is the left-most characteer.

CREATE TABLE #tmp (value varchar(10))

INSERT INTO #tmp (value) VALUES ('*dog'), ('*cat'), ('*bird')

SET value = REPLACE(value, '*', '')

SELECT * FROM #tmp  

Open in new window

LVL 66

Accepted Solution

Jim Horn earned 2000 total points
ID: 39484110
Just in case, here's the code for only the left-most character..
CREATE TABLE #tmp (value varchar(10))

INSERT INTO #tmp (value) VALUES ('*dog*'), ('*cat'), ('*bird*')

SET value = RIGHT(value, LEN(value) - 1)
WHERE LEFT(value, 1) = '*'


Open in new window


Author Closing Comment

by:Starr Duskk
ID: 39484152
perfect! thanks!
LVL 66

Expert Comment

by:Jim Horn
ID: 39484182
Thanks for the grade.  Good luck with your project.  -Jim

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question