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 2008 Forums
 Transact-SQL (2008)
 Reading XML

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2010-09-20 : 03:06:30
I have been trying to run a while loop to read sextions in xml

WHILE (@TotalErrors > 0)
BEGIN
SELECT CAST(@xmlReport.query('data (Errors/Error/ErrorItem[1]/@errorCode)') AS VARCHAR(MAX)) AS 'errorCode' ,
CAST(@xmlReport.query('data (Errors/Error/ErrorItem[1]/@errorItemType)') AS VARCHAR(MAX)) AS 'errorItemType' ,

SET @TotalErrors = @TotalErrors - 1
END

This retuns the 1st error. @TotalErrors is the number of errors, what i need to find out is how to do

SELECT CAST(@xmlReport.query('data (Errors/Error/ErrorItem[@TotalErrors]/@errorCode)') AS VARCHAR(MAX)) AS 'errorCode' ,
   

- Advertisement -