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-11-05 : 14:56:02
|
| Hi.I'd like to delete everything after the last "-" found in the string.I mean if I have these fields:L-Arginine 500 mg - 100 CapsulesL-Carnitine 250 mg - 30 CapsSAMe 400 mg Vegetarian - 30 TabletsPro-GH#8482; - 600 g (21.2 oz.)L-Arginine Powder - 1 lb....I need to get these results:L-Arginine 500 mgL-Carnitine 250 mgSAMe 400 mg VegetarianPro-GH#8482;L-Arginine Powder...please help.Thanks in advanced |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-05 : 15:03:43
|
| DECLARE @string varchar(100)set @string = 'L-Arginine 500 mg - 100 Capsules' select reverse(right(reverse(@string),len(@string) - charindex( '-', reverse(@string))) )JimEveryday I learn something that somebody else already knew |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-05 : 15:05:41
|
Well that seems to work nicelyDECLARE @string varchar(100)set @string = 'L-Arginine 500 mg - 100 Capsules'select reverse(right(reverse(@string),len(@string) - charindex( '-', reverse(@string))) )set @string = 'L-Arginine 500 mg - 100 Capsules - Bretts Tequila'select reverse(right(reverse(@string),len(@string) - charindex( '-', reverse(@string))) ) Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-11-05 : 15:14:41
|
| thank u so much it worked :) |
 |
|
|
|
|
|