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)
 string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 06/01/2012 :  06:09:35  Show Profile  Reply with Quote
How do I look for the last occurance of space and then get everything before it?
example:
@sql = 'brothers here there'
should return 'brothers here'
Thanks

arkiboys
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 06/01/2012 :  06:24:14  Show Profile  Reply with Quote
solved it by using reverse function.
Thanks anyway.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 06/01/2012 :  11:38:43  Show Profile  Reply with Quote
cool...for others sake could you please post what your final solution was?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 06/01/2012 :  12:14:36  Show Profile  Reply with Quote
used the reverse function and the charindex
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 06/01/2012 :  12:29:56  Show Profile  Reply with Quote
can you post solution using sample data for others to understand

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 06/01/2012 :  18:16:25  Show Profile  Reply with Quote
declare @data varchar(50) = 'this is a test'
declare @pos int = CHARINDEX(' ', reverse(@data), 1)

SELECT
SUBSTRING(@data, 1, len(@data) - @pos)
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