Extract Left and Right Part from a string having a format of xxxx/yyyy where x=>alphabets, y=>numbers in SQL using PARSEAME

Rajnilari2015
Posted by Rajnilari2015 under Sql Server category on | Points: 40 | Views : 289
Let's say we have a table as

Declare @t Table(Code varchar(20) )

insert into @t values('AAAA/00001')
insert into @t values('BBB/00010')
insert into @t values('CCC/00002')
insert into @t values('ZZZ/00100')


We need to Extract Left and Right Part from Code

The below code will do so

Declare @t Table(Code varchar(20) )

insert into @t values('AAAA/00001')
insert into @t values('BBB/00010')
insert into @t values('CCC/00002')
insert into @t values('ZZZ/00100')

Select
LeftPart =PARSENAME(REPLACE(Code,'/','.'),2)
,RightPart=PARSENAME(REPLACE(Code,'/','.'),1)
From @t x

Comments or Responses

Login to post response