h1

Get LASTINDEX in SQL

June 28, 2012

First create a function as folloing.

CREATE FUNCTION
CREATE FUNCTION dbo.LAST_INDEX(@STRING VARCHAR(8000), @CHAR CHAR)
RETURNS INT
AS
BEGIN
RETURN LEN(@STRING) – CHARINDEX(@CHAR, REVERSE(@STRING), 1 + 1)
END

Now you can use this like

SELECT LAST_INDEX(‘TEST.STRING’,’.’)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: