Quantcast
Channel: Answers for "Find substring saved between 2 characters"
Viewing all articles
Browse latest Browse all 10

Answer by Kev Riley

$
0
0
whilst we wait for clarification on the question, here's my take on it.... I would use a [Tally table](http://www.sqlservercentral.com/articles/T-SQL/62867/) to 'loop' and split the string. I've assumed the start is '^3^' declare @string varchar(max) set @string = '2|200911_s^3^1988415|20091452_s^3^1988411|2009152_s^3^1988455|' select substring(@string, N+4, charindex('|', @string, N+4)-N-4) from dbo.tally where N <= len(@string) and SUBSTRING(@string,N+1,3) = '^3^' gives -------- 1988415 1988411 1988455 ---------- code for Tally table IF OBJECT_ID('dbo.Tally') IS NOT NULL DROP TABLE dbo.Tally SELECT TOP 100000 IDENTITY(INT,1,1) AS N INTO dbo.Tally FROM Master.dbo.SysColumns sc1, Master.dbo.SysColumns sc2

Viewing all articles
Browse latest Browse all 10

Trending Articles