I have a table named Spool and there's a field named "NAME". This field have a string with 7 values separeted by dashes.

I must do a script in SQL Server that split the string "NAME" by the dashes and record every of the seven values in 7 different columns.

For example
NAME: abcd-0123-asd
In the column1 must record abcd, in column2: 0123 and column3 asd.. etc
I hope i have explained =)

Thanks!!

I'm using SQL 2008, also in my real problem i have 7 segments in my string "NAME" and i have to put every segment of that field in 7 columns.

Also i have n number of records in the table wich apply that script =)
Thanks for you help

---

HI John Dewey I make this:

```
Create FUNCTION  [dbo].[SPReturnThreeFields] ( @str NVARCHAR(max), @delimiter NCHAR(1) )

AS
BEGIN
    declare @strOriginal NVARCHAR(max), @f1 varchar(max), @f2 varchar(max), @f3 varchar(max), @f4 varchar(max),@f5 varchar(max),@f6 varchar(max),@f7 varchar(max), @bool int = 0;

    -- Field 1
    set @f1=(left(@str,CHARINDEX(@delimiter,@str,1)-1));
    SET @str=RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1));

    -- Field 2
    set @f2=(left(@str,CHARINDEX(@delimiter,@str,1)-1));
    SET @str=RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1));

    -- Field 3
    set @f3 = (left(@str,CHARINDEX(@delimiter,@str,1)-1));
    SET @str=RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1));

    set @f4 = (left(@str,CHARINDEX(@delimiter,@str,1)-1));
    SET @str=RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1));

    set @f5 = (left(@str,CHARINDEX(@delimiter,@str,1)-1));

    set @bool = case when patindex('%' + @delimiter + '%' , @str) <> 0 then 0 else 1 end;
    SET @str= case when @bool = 0 then RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1)) else @str end;    

    set @f6 = case when patindex('%' + @delimiter + '%' , @str) < 1 then case when @bool = 0 then @str else '' end else (left(@str,CHARINDEX(@delimiter,@str,1)-1)) end;   

    set @bool = case when patindex('%' + @delimiter + '%' , @str) <> 0 then 0 else 1 end;
    SET @str= case when @bool = 0 then RIGHT(@str,LEN(@str)-CHARINDEX(@delimiter,@str,1)) else @str end;        

    set @f7 = case when patindex('%' + @delimiter + '%' , @str) < 1 then case when @bool = 0 then @str else '' end else (left(@str,CHARINDEX(@delimiter,@str,1)-1)) end;   

    --update dbo.Spool SET Segmento1 = @f1,Segmento2 = @f2,Segmento3 = @f3,Segmento4 = @f4, Segmento5 = @f5, Segmento6 = @f6, Segmento7 = @f7 where Nombre = @strOriginal;

END

GO

```

Apparently it works fine but what if i want to make the update in the same table, how you call the function or must be a store procedure?
Thanks for your help!