Reply to Re: Concatenating strings from different rows

Your name:

Reply:


Posted by prakashdehury on 11/15/05 15:08

try with this

you also can use table variable without using #temp table.



create table tab001
(
id int,
SEQ int,
txt char(1)
)

insert into tab001 values (1,1,'A')
insert into tab001 values (2,1,'B')
insert into tab001 values (3,2,'C')
insert into tab001 values (4,2,'D')
insert into tab001 values (5,2,'E')
insert into tab001 values (6,3,'F')
insert into tab001 values (7,3,'G')



create table #tem
(
id int
)
create table #temmData
(
id int,
txtAll varchar(200)
)

insert #tem select Distinct SEQ from tab001


Declare @tSEQ int
DECLARE t_cursor CURSOR FOR
select id from #tem

declare @Notes varchar(4000)

OPEN t_cursor
FETCH NEXT FROM t_cursor INTO @tSEQ

IF @@FETCH_STATUS <> 0
print 'no ID found'

WHILE @@FETCH_STATUS = 0
BEGIN

Select @Notes = ''
Select @Notes = @Notes + ' ' + txt
>From tab001 Where SEQ = @tSEQ order by ID DESC
print @Notes
insert into #temmData values (@tSEQ, @Notes)
FETCH NEXT FROM t_cursor INTO @tSEQ

END

select * from #temmData

CLOSE t_cursor
DEALLOCATE t_cursor











Hennie7863 wrote:
> Hi,
>
> I have table which has the following values :
>
> ID SEQ Text
> 1 1 A
> 2 1 B
> 3 2 C
> 4 2 D
> 5 2 E
> 6 2 F
> 7 3 G
>
> The result should be :
>
> 1 AB
> 2 CDEF
> 3 G
>
> Could somebody help me with this? I could use an cursor but the table
> could be large and i want a fast solution.
>
> Thanx in advance...
>
> Hennie

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация