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)
 How to split the string in SQL Query

Author  Topic 

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-08-10 : 03:26:29
How to split the string in SQL Query.I need help.Very Urgent.

This is String
--------------
'Maruti/South3/A M Motors_10110DHL'

The SQL Query Result like below[Only i want middle string]
----------------------------------------------------------
South3


V.NAGARAJAN

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-10 : 03:29:42
select
parsename(replace('Maruti/South3/A M Motors_10110DHL','/','.'),2)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-08-10 : 03:36:40
quote:
Originally posted by webfred

select
parsename(replace('Maruti/South3/A M Motors_10110DHL','/','.'),2)



No, you're never too old to Yak'n'Roll if you're too young to die.



Very Thanks Webfred.

V.NAGARAJAN
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-10 : 04:05:22
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-08-10 : 05:31:29
Or:

DECLARE @s VARCHAR(500)
SET @s = 'Maruti/South3/A M Motors_10110DHL';

SELECT SUBSTRING(String, C1 + 1, C2 - 1 - C1) AS Wanted
FROM (SELECT @s) D(String)
CROSS APPLY
(
SELECT CHARINDEX('/', D.String)
) D1 (C1)
CROSS APPLY
(
SELECT CHARINDEX('/', D.String, D1.C1 + 1)
) D2 (C2)



______________________
Go to Top of Page
   

- Advertisement -