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 |
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2004-12-30 : 15:07:30
|
| Hey guys,Im just inetrested how others would approach this issue.Have a resultset with names, each ending in an integer.Nathan Skerl 1Nathan Skerl 2John Smith 1...I want to select the full name, and remove the trailing integer.Currently:SELECT REPLACE(REPLACE(partner_name, '1', ''), '2', '')Feels dirty though... :)Any thoughts?Assume the format is [FName][Space][LName][Space][Integer] |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-12-30 : 15:15:26
|
Lots of ways to do this - here is one:declare @name varchar(40)set @name = 'Nathan Skerl 1'select left(@name,len(@name)-charindex(' ',reverse(@name),1)) |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2004-12-30 : 15:19:00
|
| Thats what im talking about... I love this stuff. Well done ehorn! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-12-30 : 15:31:02
|
you could also do:select left(@name, patindex('%[0-9]%', @name)-2)Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|