Not sure on the desired output since you didn't post one.May be this ?Create FUNCTION ParseValues (@String varchar(8000) ) RETURNS @RESULTS TABLE (ID int identity(1,1), Val varchar(100) ) AS BEGIN DECLARE @Value varchar(100) WHILE @String is not null BEGIN SELECT @Value=CASE WHEN CHARINDEX(';',@String) >0 THEN LEFT(@String,CHARINDEX(';',@String)-1) ELSE @String END, @String=CASE WHEN CHARINDEX(';',@String) >0 THEN SUBSTRING(@String,CHARINDEX(';',@String)+1,LEN(@String)) ELSE NULL END INSERT INTO @RESULTS (Val) SELECT @Value END RETURN ENDselect distinct ltrim(left(val,charindex('-',val)-1) )from ParseValues( '12345-678; 123456-678; 12345-6009; 123456-6009')