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.
| Author |
Topic |
|
grimmjow40L
Starting Member
2 Posts |
Posted - 2008-01-15 : 19:15:43
|
| Hi experts,I need to do an update on a field which will update 3 characters within a string. Right now I have '000111000333'. I want to replace '000' starting from the 7th character space with '222'. The first set of zeroes will remain unchange. I want the final outcome to be '000111222333'. How can I do this?I have tried searching this forum and could not find anything. the closest thing I can find is http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81890#360936. Thanks for the help! |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-01-15 : 19:34:19
|
| Lots of possible ways. Look through "string functions" in Books Online.If you always want to replace 7th, 8th, and 9th characters with 3 characters you could use STUFF:update myTable set col = STUFF(<col>, 7, 3, '222') where ...select stuff('000111000333', 7, 3, '222')Be One with the OptimizerTG |
 |
|
|
grimmjow40L
Starting Member
2 Posts |
Posted - 2008-01-15 : 19:53:58
|
| Awesome!! thank you for your help. |
 |
|
|
|
|
|