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
 General SQL Server Forums
 New to SQL Server Programming
 Query help

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2007-03-20 : 04:26:18
i have table as follow

key list seqno
1021 abc 1
1021 xyz 2
1021 pqr 3
1022 mno 1
1022 def 2
1022 jkl 3


I want to make a single list corresponding to key.
Like

1021 abcxyzprq
1022 mnodefjkl

I have written some code but i am getting only first list abc not a abcxyzprq


alter procedure cm_list
As
begin
set nocount on
declare
@List varchar(2000),
@List1 varchar(2000),
@List2 varchar(2000),
@seqnbr numeric(12,0),
@key numeric(12,0) ,
@count2 numeric(12,0)

select @count2 = 1


declare list_cursor cursor for
select distinct List, SeqNo
from Table1
where Key = 1021


open list_cursor

fetch list_cursor into @List1,@seqnbr

while @@fetch_status = 0
begin
select @List =''
select @ist = isnull(@List,'')+ @List1
while ( @count2 <= @seqnbr )
begin
FETCH rulelist_cursor into @List1,@seqnbr
select @List = @List+ @List1
select @count2 = @count2 + 1
end
end

select @List
close list_cursor
deallocate list_cursor

return
end
GO

Plz tell me how I can get the following ouptput

1021 abcxyzprq
1022 mnodefjkl

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-20 : 04:29:48
why don't you take a look at this http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx


KH

Go to Top of Page
   

- Advertisement -