CREATE TABLE tmpPipeSepVals
(PipeSepVals VARCHAR(10))
DECLARE @strPipeSepVals
varchar(20),
@ThisValue
varchar(20),
@EndPoint
int
SET @strPipeSepVals = (SELECT
[PipeSepValCol] FROM [TABLENAME] WHERE ID = '100')
SET @strPipeSepVals = ltrim(rtrim(convert(varchar,@strPipeSepVals)))
+ '|'
SET @EndPoint
= CHARINDEX('|',@strPipeSepVals)
WHILE @EndPoint
> 0
BEGIN
SET @ThisValue = SUBSTRING(@strPipeSepVals, 1, @EndPoint - 1)
SET @strPipeSepVals = SUBSTRING(@strPipeSepVals, @EndPoint + 1, 100)
INSERT INTO [tmpPipeSepVals]([PipeSepVals]) VALUES(@ThisValue)
SET @EndPoint = CHARINDEX('|',@strPipeSepVals)
END
SELECT * FROM [tmpPipeSepVals]
DROP TABLE tmpPipeSepVals |