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 2005 Forums
 Transact-SQL (2005)
 XML Question

Author  Topic 

em00guy
Starting Member

6 Posts

Posted - 2007-03-20 : 19:45:53
I'm using a while loop to build a SQL insert string based on values in nodes of an XML object. Here is an example of what I'm attempting to do:



SET @SQL = 'insert into dbo.stuff select '

WHILE @i < 10
BEGIN
@i = @i + 1
@SQL = @SQL + @xml.value('/stuff/item' + @i ,'varchar(50)') + ', '
END


This however, is incorrect because the xml.value method only accepts string literals as parameters. Can any one think of a more clever way to accomplish this task? Thanks immeasurably.
   

- Advertisement -