我有样本数据问题与XML colunns在SQL服务器
DECLARE @Table1 TABLE (users int, ts int, name varchar(10), [1] int);
INSERT INTO @Table1 (users, ts, name, [1])
VALUES (1, 1, 'Raj', 0),
(1, 3, 'maj', 2534),
(1, 10, 'yes', 1458);
如果我尝试添加
select
'test' as 'job/branch/FBEN/opcode',
users AS 'job/branch/FBEN/opcode',
name as 'job/branch/FBEN/opcode',
[1] AS 'job/branch/FBEN/opcode/1'
from
@Table1
where
ts = 3
for xml path('xmlexecute'), elements;
我得到一个错误:
Msg 6850, Level 16, State 1, Line 14
Column name 'job/branch/FBEN/opcode/1' contains an invalid XML identifier as required by FOR XML; '1'(0x0031) is the first character at fault.
怎么能我得到如下结果:
<xmlexecute>
<job>
<branch>
<FBEN>
<opcode>1</opcode>
<opcode>3</opcode>
<opcode>maj</opcode>
<1> 2534 </1>
</FBEN>
</branch>
</job>
</xmlexecute>
XML是相当严格的 - 你不能有它以数字开头的元素名称。有关类似问题,请参阅http://stackoverflow.com/questions/4756402/field-name-with-space-problem-in-case-of-for-xml-auto-output。 –
那么我需要做的就是这个@JohnD – mohan111
Dude ...还有什么可以解决的呢?使用任何不以数字字符开头的其他字符。不是火箭科学。 –