Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace a word

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2010-07-01 : 11:40:32
I have a column name strReportName

In the I have random like like pet count by year or pet county by manufactorer.

I need to replace "pet" with "vehicle" where it appears on certain rows.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-07-01 : 11:44:56
[code]UPDATE tablename
SET strReportName = Replace(strReportName,'pet','vehicle')
WHERE (condition to select the certain rows)[/code]
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-07-02 : 05:02:42
Make sure that you want to replace pet straigtht way if it comes any where in the column value
like petal will be replaced by vehicleal.


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-02 : 05:08:57
For the given examples this would work:

update table
set strReportName = replace(strReportName,'pet coun', 'vehicle coun')
where strReportName like '%pet coun%'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-07-02 : 05:55:39
quote:
Originally posted by webfred

For the given examples this would work:

update table
set strReportName = replace(strReportName,'pet coun', 'vehicle coun')
where strReportName like '%pet coun%'


No, you're never too old to Yak'n'Roll if you're too young to die.



it can be like this to be more generalized -

update table
set strReportName = replace(strReportName,'pet ', 'vehicle ')
where strReportName like '%pet %'


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page
   

- Advertisement -