In My SQL I have String like
Declare @Temp Varchar(Max) ='Pravin Gaonkar: 12 Jan 2013 11:56:21 : Hello World 1*Makarand Sawant: 12 Jan 2013 15:36:39 : Hello World 2*Makarand Sawant: 12 Jan 2013 21:21:51 : Hello World 3 *'
I have used ‘*’ As Seprator
I want to retrieve Last String from 2nd Last * Character to Last * Character
in above example the resultant string would be
Makarand Sawant: 12 Jan 2013 21:21:51 : Hello World 3
MY Query
SELECT Reverse(Left(Reverse(@Temp), Charindex('*', Reverse(@Temp)) -1))
But it is giving me error Invalid length parameter passed to the LEFT or SUBSTRING function.
Database is SQL SERVER 2008
This assumes no characters after the final
*and that you have at least 2*overall.Personally, I would store this in separate clauses and split it in the client code. Java and .net have far better string handling than SQL Server