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.
| Author |
Topic |
|
shubhada
Posting Yak Master
117 Posts |
Posted - 2007-03-20 : 04:26:18
|
| i have table as followkey list seqno1021 abc 11021 xyz 21021 pqr 31022 mno 11022 def 21022 jkl 3I want to make a single list corresponding to key.Like 1021 abcxyzprq 1022 mnodefjklI have written some code but i am getting only first list abc not a abcxyzprqalter procedure cm_listAs begin set nocount ondeclare @List varchar(2000), @List1 varchar(2000), @List2 varchar(2000), @seqnbr numeric(12,0), @key numeric(12,0) , @count2 numeric(12,0) select @count2 = 1declare list_cursor cursor forselect distinct List, SeqNo from Table1where Key = 1021open list_cursorfetch 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 @Listclose list_cursordeallocate list_cursorreturn end GOPlz tell me how I can get the following ouptput1021 abcxyzprq 1022 mnodefjkl |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|