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 |
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-05-21 : 06:21:49
|
I need to get last word in a string value.for example the string is 'qwer oiop jkl sda dfwe asd lkw' and my wanted sub string is "lkw". |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-21 : 06:28:01
|
[code]SELECT REVERSE(LEFT(REVERSE(String),CHARINDEX(' ',REVERSE(String) + ' ')-1)) AS LastpartFROM table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-05-21 : 07:52:38
|
Thank you, the code is fine |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-21 : 08:14:39
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2013-05-21 : 12:30:26
|
SELECT RIGHT(string, CHARINDEX(' ', REVERSE(String) + ' ') - 1 )FROM dbo.tablename |
|
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-05-21 : 14:03:39
|
quote: Originally posted by ScottPletcher SELECT RIGHT(string, CHARINDEX(' ', REVERSE(String) + ' ') - 1 )FROM dbo.tablename
fantastic, thanks |
|
|
|
|
|