(EP)Z!!!
No need of STUFF. (very old code)
declare @t table (PersonID int, AreaCode varchar(10), Exchange varchar(10), Root
varchar(10))
declare @t1 table (PersonID int, phone varchar(2048))
declare @pn varchar(2048), @Pid int
insert @t
select 10001, '555', '555', '5555'
union all
select 10002, '444', '444', '4444'
union all
select 10001, '555', '555', '5511'
union all
select 10001, '555', '555', '5511'
union all
select 10001, '555', '555', '5522'
union all
select 10001, '555', '555', '5533'
union all
select 10002, '555', '555', '1234'
union all
select 10003, '555', '555', '3333'
declare per cursor for select distinct personid from @t
open per fetch next from per into @pid
while @@FETCH_STATUS =0
begin
select @Pn = IsNull(@pn + ', ','') + (AreaCode+'-'+Exchange+'-'+ root) from @t where
PersonID = @pid
insert @t1 select @pid, @pn
fetch next from per into @pid
set @pn = null
end
close per
deallocate per
select * from @t1
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.