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
 Transact-SQL (2000)
 Cursor Conversion Help

Author  Topic 

gwhiz
Yak Posting Veteran

78 Posts

Posted - 2002-06-07 : 18:04:05
I have some cursors that are basically written to create XML code. Does anyone see a way to write this other than using a cursor.

Declare swl_Cursor Cursor for
Select dbo.string_ID(Sold_Product_ID), dbo.String_ID(Subscriber_ID), STD_Rate from SWL_Output


OPEN swl_Cursor
FETCH NEXT FROM swl_Cursor INTO
@spID,@sub_iD, @STD_Rate

WHILE (@@FETCH_STATUS = 0)
BEGIN
SET @TEMPSTRING = ' <SWLOUTPUT SOLD_PRODUCT_ID = "' + @SPID +
'" SUBSCRIBER_ID="' + @SUB_ID +
'" STD_RATE="' + @STD_RATE + '"/>' + CHAR(13) + CHAR(10)
UPDATETEXT #OUTXML.OUTXML @STRPTR NULL NULL @TEMPSTRING



SET @SWLCOUNT = @SWLCOUNT +1

FETCH NEXT FROM SWL_CURSOR INTO
@SPID,@SUB_ID, @STD_RATE
END


Thanks
Mike

jasper_smith
SQL Server MVP &amp; SQLTeam MVY

846 Posts

Posted - 2002-06-07 : 19:28:33
Whats wrong with FOR XML AUTO ??

Select dbo.string_ID(Sold_Product_ID) SOLD_PRODUCT_ID ,
dbo.String_ID(Subscriber_ID) SUBSCRIBER_ID,
STD_Rate STD_RATE
from SWL_Output [SWL_OUTPUT]
FOR XML AUTO


Go to Top of Page
   

- Advertisement -