| Author |
Topic |
|
wided
Posting Yak Master
218 Posts |
Posted - 2011-05-11 : 09:43:13
|
| HelloI have a field of type textthe field content:7834 / 00085301000847 / 0019864147 / 0019974I want to extract only the data after the '/ ' no spacesthanks |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-05-11 : 09:47:48
|
| DECLARE @MyVal VARCHAR(20)SET @MyVal ='7834 / 0008530' SELECT SUBSTRING (@MyVal,CHARINDEX('/',@MyVal)+2,LEN(@MyVAl)-CHARINDEX('/',@MyVal))--------------------------http://connectsql.blogspot.com/ |
 |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2011-05-11 : 09:54:25
|
| Thanks lionofdezertit is okbut why +2 |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-05-11 : 10:06:19
|
| CHARINDEX('/',@MyVal) Will return location of '/', suppose its 6 in above case but we need our string from possition 8 as we know that / will follow a space so we will also skip these two characters--------------------------http://connectsql.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-05-11 : 10:09:40
|
| OR YOU USESELECT REVERSE(SUBSTRING(REVERSE(@MyVal),1,CHARINDEX(' ',REVERSE(@MyVal))-1))--------------------------http://connectsql.blogspot.com/ |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-05-11 : 10:10:09
|
| SELECT PARSENAME(REPLACE(@str,' / ','.'),1)SELECT STUFF(@str,1,CHARINDEX(' / ',@str)+3,'')JimEveryday I learn something that somebody else already knew |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-05-11 : 10:40:54
|
| wow, i liked the PARSENAME idea--------------------------http://connectsql.blogspot.com/ |
 |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2011-05-11 : 10:52:56
|
| okthanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-05-12 : 03:17:16
|
| orselect RIGHT(@str,charindex('/',@str)+1)MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-05-12 : 03:22:23
|
quote: Originally posted by jimf SELECT PARSENAME(REPLACE(@str,' / ','.'),1)SELECT STUFF(@str,1,CHARINDEX(' / ',@str)+3,'')JimEveryday I learn something that somebody else already knew
The second method should be SELECT STUFF(@str,1,CHARINDEX(' / ',@str)+2,'')MadhivananFailing to plan is Planning to fail |
 |
|
|
|