1

select:
select top 2 name, crdate from sys.sysobjects where xtype = 'u' for xml raw('object')

产生与此类似的结果

<object name="table_name1" crdate="2010-05-03T09:34:08.150" />
<object name="table_name2" crdate="2011-04-17T11:19:18.157" />

有什么办法可以用变量(如@RowName)代替“对象”这个词?
提前致谢

4

2 回答 2

1

您可以使用动态 SQL

declare @s nvarchar(4000)
select @s ='select top 2 name, crdate from sys.sysobjects where xtype = ''u'' for xml raw('''+@rowname+''')'
exec sp_executesql @s
于 2012-10-23T13:05:23.730 回答
0
set @xml.modify('declare default element namespace "http://www.someurl.com";
                     insert <root>root> ');

set @xml.modify('insert <child1><test1></test1></child1> as last into (/*:root)[1]');   
set @xml.modify('insert <child2><test2></test2></child2> as last into (/*:Root[1]/*:Child1[1])');
于 2014-01-30T22:08:41.060 回答