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 2008 Forums
 Transact-SQL (2008)
 Separate string from orignal string

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2013-12-17 : 22:03:55
Hi Expert,

I have a requirements to separate an string from the original string the reference is the -. my issue here is how could i get the last 3 chr. If there is a double L need to take out the one L. Your reply is very much appreciated. thanks.

Sample DDL


Create table #sample
(Location nvarchar(15))
insert into #sample(Location) values('MARKET-L5')
insert into #sample(Location) values('P-LL15')
insert into #sample(Location) values('MARKET-L4')
insert into #sample(Location) values('market-la')
insert into #sample(Location) values('P-LL15')
insert into #sample(Location) values('Market-L15')
insert into #sample(Location) values('Market-L15')
insert into #sample(Location) values('Market-RMA')
insert into #sample(Location) values('P-LL16')

Result
Location --- Result
Market-L15---L15
Market-L3----L3
MARKET-L5----L5
P-LL15-------L15
MARKET-L4----L4
market-la----la
P-LL15-------L15
Market-L15---L15
Market-L15---L15
Market-RMA---RMA
P-LL16 ---L16







khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-17 : 22:07:04
[code]replace(right(Location, 3), '-', '')[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2013-12-17 : 22:21:09
Thank you very much khtan.
Go to Top of Page
   

- Advertisement -