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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Updating a Sub Set of a String

Author  Topic 

batcater98
Starting Member

22 Posts

Posted - 2008-01-03 : 09:48:22
I am wanting to update a portion of a string in a field while leaving the rest of the string as is.

Example:

ftp://mydata/is/Year_2007/here.dat

I want to change just the 2007 to 2008 and leave the rest in tack. I need to do this over multiple records.

Suggestions.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-03 : 09:50:11
[code]update table
set col = replace(col, ' 2007/', ' 2008/')
Where <condition>[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-03 : 09:50:42
EDIT:


update <yourTable> set
<column> = replace(<column>, 'Year 2007', 'Year 2008')

Be One with the Optimizer
TG
Go to Top of Page

batcater98
Starting Member

22 Posts

Posted - 2008-01-03 : 10:09:45
Thanks for the quick reply - that is exactly what I was needing.
Go to Top of Page
   

- Advertisement -