SQL query Select text between to forward slashes

I have a text in the following format
"/xxx/yyy/zzz"
and I would like to select only the text between the first two forward slashes i.e. (xxx)
how do I do that in SQL query  
I have been trying to use

select substring (column,CHARINDEX('/',column)
,CHARINDEX('/',column)+len(column) - CHARINDEX('/',reverse(column))) as ColumnName

but that returns /xxx/yyy/zzz and NOT /xxx/

Thank you for your help in advanced !
UKITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
I have need of things like that enough, to where I created a function to handle it for me, so that I could write my query like this:

SELECT dbo.ufnSplit('/', '/xxx/yyy/zzz', 1)

Here's the function. :)
CREATE FUNCTION ufnSplit (
	@sep	char(1)		= ',',
	@str	varchar(512)= null,
	@ndx	smallint	= 0)
RETURNS varchar(80)
AS
BEGIN
	DECLARE	@piece	varchar(80);
	SET	@ndx = @ndx + 1;

	WITH Pieces(pn, start, stop) AS (
		SELECT 1, 1, CHARINDEX(@sep, @str)
		UNION ALL
		SELECT pn + 1, stop + 1, CHARINDEX(@sep, @str, stop + 1)
		FROM Pieces
		WHERE stop > 0
	)
	SELECT	@piece = SUBSTRING(@str, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END)
	FROM	Pieces
	WHERE	pn = @ndx;

	RETURN @piece;
END

Open in new window

The "ufn" prefix simply means "user function".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
Try this:
SELECT SUBSTRING(column, CHARINDEX('/',column)+1, CHARINDEX('/',column,CHARINDEX('/',column)+1)-2)

Open in new window

UKITAuthor Commented:
PERFECT THANK YOU SIR WORKED AS A CHARM THANK YOU !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.