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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Last Word

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 Lastpart
FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-05-21 : 07:52:38
Thank you, the code is fine
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-21 : 08:14:39
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-05-21 : 12:30:26
SELECT RIGHT(string, CHARINDEX(' ', REVERSE(String) + ' ') - 1 )
FROM dbo.tablename
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -