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)
 Simple Procedure

Author  Topic 

mdanwerali
Starting Member

30 Posts

Posted - 2002-11-01 : 06:56:09
Hi ,

My procedure will fetch more than one record, then i want to concatenate those records and store in a field..

for that i am using Set A = A +B....

but Set should not be used in procedure then how to handle this problem..

My Procedure is something like this
---
ALTER Procedure topiccontent(@topicid nchar(10),@topicdetails varchar(8000) OUTPUT)
as

Declare c Cursor for select tpmdetails
from topicmaster
where tpmtopicid = @topicid
or (tpmowner =@topicid
and tpmname like '%Cont...')
order by tpmtopicid
Declare @tpcdetails varchar

OPEN c
FETCH NEXT FROM c INTO @topicdetails

WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM c INTO @topicdetails
END

CLOSE c
DEALLOCATE c

--here how to store the details in a variable and send it as a output varaibale.------?

for eg: i have three records...
rec 1 : aaaa
rec 2 : bbbb
rec 3 : cccc

and the output value shld be aaaabbbbcccc
how to do this.. please help me

anwer

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-11-01 : 07:51:40
You should read Garth's article on Using COALESCE to Build Comma-Delimited String. Except, instead of using a comma to delimit the string, it looks like you want to use a '' {empty string} ...

Jay White
{0}
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2002-11-01 : 08:05:38
I've never used cursors. Here's a set based method that should work.

declare @allnames varchar (4000)
set @allnames = ''
SELECT @allnames = @allnames + tpmdetails
FROM
(SELECT Top 100 percent tpmdetails FROM topicmaster ORDER BY tpmtopicid) MySet
Print @allnames
----------------------------
Sam


Go to Top of Page
   

- Advertisement -