Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split function

Status
Not open for further replies.

faithful1

Programmer
Sep 27, 2002
49
0
0
US
Please help. this would seem to be very easy, but turning into a nightmare for me.
I need a split function that returns the last section of a string delimited by a given character.

For example, I would like to split 'test-01-02' by '-' and have it return 02. Please help. Thanks!
 
string functions vary from one database system to the next

it would probably be best if you post this question in the forum for your particular database system

in mysql, for example, you would use

SUBSTRING_INDEX('test-01-02', '-', -1)

r937.com | rudy.ca
 
SQL SERVER 2000

you could convert the following into a user defined function?
Code:
DECLARE @StringProvided 		VARCHAR(50),
	@Position1 			INT,
	@StringRequired 		VARCHAR(50)

--example string
SET @StringProvided = 'lkjl-hand-oxen'

SET @Position1 = (SELECT CHARINDEX('-', @StringProvided))


SET @StringRequired = RIGHT(@StringProvided, LEN(@StringProvided) - 
(SELECT CHARINDEX('-',@StringProvided, @Position1 + 1)))



SELECT @StringRequired

BlueCJH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top