How to write split Query in sql [Resolved]

Posted by Jayakumars under ASP.NET on 7/21/2015 | Points: 10 | Views : 768 | Status : [Member] [MVP] | Replies : 4
Hi
Bandi

I need split string here no need function only sql query.

Create table Test1
(
id int primary key identity(1,1),
Ename varchar(50)
)

Insert into Test1 values('\\PCNAME\Docs\Reports\Rpt.Rdlc')
Insert into Test1 values('\\PCNAME\Docs\Reports\1.rpt')
Insert into Test1 values('\\PCNAME\Docs\Reports\5.xml')


Select * from Test1

--- I need output this

-- Id Ename
1 Rpt.Rdlc
2 1.rpt
3 5.xml

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Bandi on: 7/21/2015 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved

SELECT ID, RIGHT( Ename, CHARINDEX('\',REVERSE('\'+Ename ))-1)
FROM Test1


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 7/21/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SELECT ID, RIGHT( Ename, CHARINDEX('\',REVERSE(Ename))-1)
FROM Test1


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 7/21/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi
bandi

error comes this

Invalid length parameter passed to the RIGHT function.

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chandrikafk on: 7/29/2015 [Member] Starter | Points: 25

Up
0
Down
hi bandi
can u please solve my problem.

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response