SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Last Word
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 05/21/2013 :  06:21:49  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 05/21/2013 :  06:28:01  Show Profile  Reply with Quote
SELECT REVERSE(LEFT(REVERSE(String),CHARINDEX(' ',REVERSE(String) + ' ')-1)) AS Lastpart
FROM table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 05/21/2013 06:28:28
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 05/21/2013 :  07:52:38  Show Profile  Reply with Quote
Thank you, the code is fine
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 05/21/2013 :  08:14:39  Show Profile  Reply with Quote
welcome

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

ScottPletcher
Constraint Violating Yak Guru

USA
348 Posts

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

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 05/21/2013 :  14:03:39  Show Profile  Reply with Quote
quote:
Originally posted by ScottPletcher

SELECT RIGHT(string, CHARINDEX(' ', REVERSE(String) + ' ') - 1 )
FROM dbo.tablename


fantastic, thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000