Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parse a string
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/29/2012 :  14:59:05  Show Profile  Reply with Quote

I need to parse a string by the delimeter "/".

for example, string= /usr/open/windows/whatever/blah/
I need to break up the string. I really only need the first 3 levels so in this case, level1 = /usr, level2 = /open, and level3 = /windows.


I read the suggested article and the examples are very confusing any other suggestions are appreciated. I prefer a query rather than a procedre because I've never used a procedure before.

Edited by - strattonm on 11/29/2012 16:00:46

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/29/2012 :  15:09:15  Show Profile  Reply with Quote
Using a string splitter such as the one in Jeff Moden's article here would probably be the best way:

Copy the function in Fig 21 of that article and then use it as
SELECT * FROM MASTER.dbo.DelimitedSplit8K(YourStringHere,'/')
Go to Top of Page

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/29/2012 :  19:39:16  Show Profile  Reply with Quote
Actually, the method I described is probably the simplest. Just follow these steps exactly:

1. Copy the code in Fig. 21 of that article.

2. Open a SSMS query window, set the database to your database from the dropdown, paste the copied code to that window and click execute. Now close that window.

3. Open another SSMS query window and type the query:

declare @str varchar(256) = 'string= /usr/open/windows/whatever/blah/';
SELECT * FROM dbo.DelimitedSplit8K(@str,'/');

4. Take a look at the output - it will have the data you need, nicely split.

Give it a try, and you will love it
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000