SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

strattonm
Starting Member

1 Posts

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

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

for example, string= /usr/open/windows/whatever/blah/blah.sh
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.

thanks!

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

sunitabeck
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: http://www.sqlservercentral.com/articles/Tally+Table/72993/

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

sunitabeck
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/blah.sh';
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000