To break a string into several parts

SQL 2000

declare @a varchar(100)
set @a = '6125.349.5601.278.90.black.blue'

The variable @a hold seven different values seperated by '.'
I have a table where a column holds data whoose pattern is exactly like above.
Now I want to break the abve value into seven different columns.
Like
value1=6125
value2=349
value2=5601
value4=278
value5=90
value6=black
value7=blue

All the values should be shown in one row.
Is it possible to do this without using function?
Is it possible to do through select statement?

I want to update the table having columns value1,value2, value3,value4,value5,value6,value7

MTNN

MehramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
you can do this without a function, but requires a lot of coding  

declare @a nvarchar(4000)
declare  @tbl table (s varchar(1000))
DECLARE @i int ,@j int
SELECT       @i = 1
set @a = '6125.349.5601.278.90.black.blue'


WHILE @i <= len(@a)
BEGIN
      SELECT      @j = charindex('.', @a, @i)
      if @j = 0
      BEGIN
            SELECT      @j = len(@a) + 1
      end
      INSERT      @tbl SELECT substring(@a, @i, @j - @i)
      SELECT      @i = @j +1
END

SELECT * from @tbl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pratima PharandeCommented:
declare @sInputList varchar(100)
set @sInputList = '6125.349.5601.278.90.black.blue'
DECLARE @Item Varchar(8000)
declare @Delimiter varchar(1)
set @Delimiter = '.'

WHILE CHARINDEX('.',@sInputList,0) <> 0
BEGIN
SELECT
@Item=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@Delimiter,@sInputList,0
)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@Delimiter,@sInputList,0)+1,LEN(@sInputList))))


IF LEN(@Item) > 0
print @Item
end
print @sInputList


try this here you will get the seperateditem ..
now update it  @Item to your table & for last itme @sInputList
0
MehramAuthor Commented:
Hi experts

I am getting the result in the shape of array.
I am having
6125
349
5601
278
90
black
blue
into single variable/column.

I want to have like
@col1=6125.@colb=349,@clc=5601, @coldd=278 ............  all in one row
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Pratima PharandeCommented:
declare @sInputList varchar(100)
set @sInputList = '6125.349.5601.278.90.black.blue'
DECLARE @Item Varchar(8000)
declare @Delimiter varchar(1)
declare @cnt int
set @Delimiter = '.'
set @cnt = 1
WHILE CHARINDEX('.',@sInputList,0) <> 0
BEGIN
SELECT
@Item=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@Delimiter,@sInputList,0
)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@Delimiter,@sInputList,0)+1,LEN(@sInputList))))


IF LEN(@Item) > 0
print  '@col' + convert(varchar(1),@cnt)+ '=' + @Item
set @cnt = @cnt + 1
end
print  '@col' + convert(varchar(1),@cnt)+ '=' + @sInputList
0
perezjosCommented:
0
ee_rleeCommented:
try this

SELECT * FROM urTable
WHERE (CAST(column1 AS VARCHAR(20)) + '.' +
             CAST(column2 AS VARCHAR(20)) + '.' +
             CAST(column3 AS VARCHAR(20)) + '.' +
             CAST(column4 AS VARCHAR(20)) + '.' +
             CAST(column5 AS VARCHAR(20)) + '.' +
             CAST(column6 AS VARCHAR(20)) + '.' +
             CAST(column7 AS VARCHAR(20))) = @a
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.