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)
 string

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-06-01 : 06:09:35
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
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-06-01 : 06:24:14
solved it by using reverse function.
Thanks anyway.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-01 : 11:38:43
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
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-06-01 : 12:14:36
used the reverse function and the charindex
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-01 : 12:29:56
can you post solution using sample data for others to understand

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

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-06-01 : 18:16:25
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
   

- Advertisement -