Hi All I know many people in this forum are dead against cursors and I am begining to understand why. so I am requesting assistance with the following Stored proc that produces hardcoded XML and stores it in the database. The stored procedure uses a cursor to loop throught a set of records and then produce XML data for each record. Can any one show me how:1. I can eliminate the use of the cursor ;2 Get rid of the hardcoded XML tags and produce The XML with the XML funcionaility that is shipped with SQL server.I have over 55 stored procedures that use this method and this is one of the smaller ones, I would appreciate if any one can advise on how I can improve performance and code.Good Luck 
DROP PROC spXMLOutput_LastMonthVolgoCREATE PROC spXMLOutput_LastMonthVol@Clearall BIT = 0,@ClearISIN VARCHAR(20) = NULLASBEGINDECLARE @return_status int, @databaseName VARCHAR(50)SELECT @databaseName = DB_NAME(DB_ID())EXEC @return_status = spSendMessages @databaseNameIF @return_status = 0 RETURNSET NOCOUNT ONDECLARE @TempDate VARCHAR(12)select @tempDate = CONVERT(VARCHAR(12),DATEADD(mm,-1,getdate()),112)SELECT @TempDate = SUBSTRING(@TempDate,1,4) + SUBSTRING(@TempDate,5,2)-- varaibles neededDECLARE @Vol VARCHAR(30), @ISIN VARCHAR(30) -- Get the data from vMarksDECLARE curVol CURSOR FORselect isin,CONVERT(VARCHAR(30), sum(ISNULL(volume,0)) )from t1..companyMonthlySummary (NOLOCK)where yearmonth = @TempDategroup by ISINORDER BY ISINIF @Clearall = 1BEGINSELECT @vol = ' 'SELECT @ISIN = @ClearISINENDOPEN curVolFETCH NEXT FROM curVol INTO @ISIN, @VolWHILE @@FETCH_STATUS = 0BEGININSERT INTO XML1..ML1Messages (ID,ISIN,Subscriber,Datecreated,Message,XMLText1)VALUES (@ID,@ISIN,'TEST1',Getdate(),'MESSAGE1' '<MESSAGE>' + char(13) + char(10) + ' <HEADER>' + char(13) + char(10) + ' <MESSAGETYPE>TEST1</MESSAGETYPE>' + char(13) + char(10) + ' <ISIN>' + @ISIN + '</ISIN>' + char(13) + char(10) + ' </HEADER>' + char(13) + char(10) + ' <BODY>' + char(13) + char(10) + ' <LastMonthVol>' + @Vol + '</LastMonthVol>' + char(13) + char(10) + ' </BODY>' + char(13) + char(10) + '</MESSAGE>' + char(13) + char(10) ) FETCH NEXT FROM curVol INTO @ISIN, @VolENDCLOSE curVolDEALLOCATE curVolSET NOCOUNT OFFENDgoGRANT ALL ON spXMLOutput_LastMonthVol to PUBLICgo
Thanxs OMB