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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get data within slashes

Author  Topic 

deepsmehta
Starting Member

4 Posts

Posted - 2008-08-04 : 19:42:37
Hi
In one of the columns of my table it shows the path of Reports like following.

/Product/Customer/Aging
/Information/Asset/Dest
/Term/Auto/Red
/Fees/Detail/Blue


But i want only first word from L-R within Slashes. i want my result set to be look like
------------------
Product
Information
Term
Fees

Any Idea?

Thanks
Deeps

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-04 : 19:57:41
DECLARE @s varchar(50)

SET @s = '/Product/Customer/Aging'

SELECT SUBSTRING(@s, 2, CHARINDEX('/', SUBSTRING(@s, 2, DATALENGTH(@s))) - 1)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-05 : 04:55:16
or try this if data dont have more than 4 slashes

select parsename(col,3) from
(
select replace(col,'/','.') as col from table
) as t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -