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 |
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-01-05 : 16:46:00
|
| Hi.I have a table with diffrent values like this:14280_aljuc_1.jpg 14280_aljuc_3.jpg14280_LBL.jpg 14280_SUP.jpg 100_Fkidbld_3.jpg110_Fkidbld_1.jpg1001_Soothing_1.jpg10100_Half_1.jpg...if there is a middle part I want to delete that.which means I need to have these results:14280_1.jpg 14280_3.jpg14280_LBL.jpg 14280_SUP.jpg 100_3.jpg110_1.jpg1001_1.jpg10100_1.jpgplz help.thanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-01-05 : 19:08:39
|
| As long as you want everything to the right of the first "_"declare @var varchar(80)set @var = '10100_Half_1.jpg' select right(@var,len(@var)-charindex('_',@var))Jim |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-05 : 21:13:55
|
| Here is my shot:declare @t table(pic varchar(100))insert @tselect '14280_aljuc_1.jpg' union allselect '14280_LBL.jpg' union allselect '14280_LBL.jpg' union allselect '14280_SUP.jpg' union allselect '100_3.jpg' union allselect '110_1.jpg' union allselect '1001_1.jpg' union allselect '10100_1.jpg'SELECT case when pic like '[0-9]%_[a-z]%_[0-9]%.jpg' then STUFF(pic, charindex('_',pic)+1,len(pic)- charindex('_',pic), right(pic,5))else pic end from @t |
 |
|
|
|
|
|