RE: Problem With Cursor ! (Urgent)

RE: Problem With Cursor ! (Urgent)

 

  

Hi Usman,

Here is the solution. You need to declare a temp varriable let say [ @tp
]
And also initialise the temp varriable with blank char. Remember not with
NULL value, then it won't work.

DECLARE CUR_Temp CURSOR FOR
SELECT Des FROM #Temp
DECLARE @t varchar(100)
Select @tp = ''

OPEN CUR_Temp
DECLARE @Des VarChar(50)

FETCH NEXT FROM CUR_Temp INTO @Des
WHILE @@FETCH_STATUS = 0
BEGIN

Set @tp = @tp + @Des + ';'

FETCH NEXT FROM CUR_Temp INTO @Des
END
PRINT @tp
CLOSE CUR_Temp
DEALLOCATE CUR_Temp



Cheers,

Sushant


-----Original Message-----
From: Usman Farhat [mailto:Usman.[Email Address Removed] 29 November 2002 14:28
To: LazyDBA.com Discussion
Subject: Problem With Cursor ! (Urgent)


Hi Guys !

This is a sample of a Cursor ! I am giving a sample of problem i got , In
The End OF Cursor In "Print @Des" I want Results As Follow

A;B;C;
While I am Just Getting
C;
Can you please Point Me Out , what is missing !


-- Here Is Table With Data
Create Table #Temp (Des Varchar(10))
Insert Into #Temp Values ('A') GO
Insert Into #Temp Values ('B') GO
Insert Into #Temp Values ('C') GO

-- Here Goes Cursor !

DECLARE CUR_Temp CURSOR FOR
SELECT Des FROM #Temp

OPEN CUR_Temp
DECLARE @Des VarChar(50)

FETCH NEXT FROM CUR_Temp INTO @Des
WHILE @@FETCH_STATUS = 0
BEGIN
Set @Des = @Des + ';'
FETCH NEXT FROM CUR_Temp INTO @Des
END
Print @Des
CLOSE CUR_Temp
DEALLOCATE CUR_Temp



Thanks For you People Concerns !

---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed] Any views or opinions expressed in this e-mail and its attachments are solely those of the author and do not necessarily represent those of PIMS UK Limited.
Confidentiality: This e-mail and its attachments are solely intended for the ordinary user of the e-mail address to which it was addressed and may be confidential. If they have come to you in error you must take no action based on them, nor must you copy or show all or any of them to anyone. If you receive this e-mail in error, we should be obliged if you would e-mail our postmaster at [Email Address Removed] and highlight the error. Thank you.
Security Warning: Please note that this e-mail has been created in the knowledge that internet e-mail is not a 100% secure communications medium. We advise that you understand and observe this lack of security when e-mailing us.
Viruses: Although we have taken steps to ensure that this e-mail and attachments are free from any virus, we advise that in keeping with good computing practice the recipient should ensure they are actually virus free.
MS Sql Server LazyDBA home page