SQL - Update part of a field

I have a field which I need to updated but it has a pipe so not the entire field can be updated.

Example (using dummy data)
Camaro | Corvette
Camaro | Corvette
Camaro | Corvette
Camaro
Camaro | Corvette

I need to update Camaro with Acura using a SQL statement.

Thanks.
LVL 2
CipherISAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Without knowing any other requirements, use the REPLACE function to replace fragments of character values..
UPDATE YourTable
SET ColumnName = REPLACE(YourColumnName, 'Camaro', 'Acura') 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kyle AbrahamsSenior .Net DeveloperCommented:
You can just use the replace:

Update <tbl>
set <field> = replace (<field>, 'Camaro', 'Acura')
-- where ?
0
Scott PletcherSenior DBACommented:
Here's how to insure that you only update the description to the left of a pipe, if a pipe exists:

UPDATE dbo.table_name
SET column_name = REPLACE(LEFT(column_name, CHARINDEX('|', column_name + '|')), 'Camaro', 'Acura') +
    SUBSTRING(column_name, CHARINDEX('|', column_name + '|') + 1, 8000)WHERE description LIKE '%Camaro%'
0
CipherISAuthor Commented:
Thank You, works great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.