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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-07 : 07:30:46
|
| Joanne writes "Hey guys, I have a string in the form of DC_0 Joanne Joanne Joanne 1_1-1. I am looking to return only the Joanne Joanne Joanne paert of the string. However the string could also be in the format DC_0 Joanne Joanne 1_1-1, where in that case i would only want to return Joanne Joanne.Any ideas?Thanks in advance for your help" |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-06-07 : 07:46:38
|
| DECLARE @variable VARCHAR(255)--SELECT @variable = 'DC_0 Joanne Joanne Joanne 1_1-1'SELECT @variable = 'DC_0 Joanne Joanne 1_1-1'SELECT @variable = RTRIM(LTRIM(REPLACE(REPLACE(@variable,'DC_0',''),'1_1-1','')))SELECT @variableMeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2004-06-07 : 08:21:02
|
[code]declare @someVariable varchar(50)set @someVariable = 'DC_0 Joanne Joanne 1_1-1'select ltrim(rtrim(substring(@someVariable, charindex(' ', @someVariable), len(@someVariable) - (charindex(' ', @someVariable) + charindex(' ', reverse(@someVariable))))))[/code]------------->>> BREAKING NEWS!!! <<<------------- Saddam Hussien has weapons of mass destrcution |
 |
|
|
|
|
|