Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help !! Simple SQL Query

Author  Topic 

akki
Starting Member

14 Posts

Posted - 2003-07-01 : 00:20:13
I have a table with only one field. Each record is contains a string like ABC,DEFGH,IJ,KLMNO,PQRSTUWX,YZ

and this table is having 5 records. like

ABC,DEFGH,IJ,KLMNO,PQRSTUWX,YZ
THIS,IS,NEXT,REC2
REC3
LMNO,THIS,IS,4TH
AND,THE,LAST

Can I write a SQL Query to insert into another table like

ABC
DEFGH
IJ
.
.
.
.
.
.
.
.
LAST

Thank you,
Akki.


Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-07-01 : 03:35:19
declare @i int, @s varchar(50), @ss varchar(8000)
set @i=1 set @s='' set @ss=''
select @ss=@ss+MyField+',' from MyTable
while @i<=len(@ss)
begin
if substring(@ss,@i,1)<>','
set @s=@s+substring(@ss,@i,1)
else
begin insert into MyNewTable select @s set @s='' end
set @i=@i+1
end

select * from MyNewTable

Go to Top of Page

akki
Starting Member

14 Posts

Posted - 2003-07-01 : 03:44:01
Thank you very much

--akki.

Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-07-01 : 03:50:43
You are welcome at any time, akki! :)

Go to Top of Page
   

- Advertisement -