| Author |
Topic |
|
gongxia649
So Suave
344 Posts |
Posted - 2006-11-15 : 15:02:31
|
| i just wanna replace the last word 'roa' to 'road'what is wrong with my code. I dont relaly see any problem. But it's replaceing all the 'roa' to 'road'.declare @table table(ad_str1 varchar(20))insert @table select 'street road roa' union allselect 'street street'select ltrim(right(ad_str1, charindex(' ', reverse(ad_str1)))) from @tableupdate @tableset ad_str1 = replace(ad_str1, ltrim(right(ad_str1, charindex(' ', reverse(ad_str1)))), 'road')where ltrim(right(ad_str1, charindex(' ', reverse(ad_str1)))) = 'roa'select * from @table |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-15 : 15:09:57
|
If that's really all you want, then this will do it.declare @table table(ad_str1 varchar(20))insert @table select 'street road roa' union allselect 'street street'update @tableset ad_str1 = ad_str1 + 'd'where right(ad_str1, 4) = ' roa'select * from @table |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-15 : 15:11:22
|
| Are you still fighting with this project?update @tableset ad_str1 = ad_str1 + 'd'where ad_str1 like '%roa'Peter LarssonHelsingborg, Sweden |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
gongxia649
So Suave
344 Posts |
Posted - 2006-11-15 : 15:12:07
|
| i also want to know why my code doesnt work. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-15 : 15:25:08
|
ouch brett, ouch! Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
gongxia649
So Suave
344 Posts |
Posted - 2006-11-15 : 15:29:15
|
| so anyone know why my code is not working? |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-15 : 15:42:23
|
quote: Originally posted by gongxia649 so anyone know why my code is not working?
Because it says replace all occurrences of 'roa' with 'road'. |
 |
|
|
gongxia649
So Suave
344 Posts |
Posted - 2006-11-15 : 16:33:50
|
quote: Originally posted by snSQL
quote: Originally posted by gongxia649 so anyone know why my code is not working?
Because it says replace all occurrences of 'roa' with 'road'.
oh. yeah i can see that now. |
 |
|
|
|