我正在尝试执行以下查询:
SELECT CASE CAST(a.AnswerText as XML).value('(/AnswerData/Input[@Name = "AnswerData0"]/Value)[1]', 'varchar(100)')
WHEN 'Other' THEN 'Self'
WHEN 'man' THEN 'Manager'
WHEN 'sub' THEN 'Suborbinate'
WHEN 'Colleague' THEN 'Colleague'
ELSE (CAST(a.AnswerText as XML).value('(/AnswerData/Input[@Name = "AnswerData0"]/Value)[1]', 'nvarchar(100)'))
END as RelationShip, ta.TestAssignmentId
这只是一个更大查询的片段,但这是导致错误的地方。输出的错误是:
XML parsing: line 1, character 67, illegal name character
我意识到这是 XML 的问题,所以我检查了 XML,对我来说似乎没问题:
<AnswerData><Input Name="AnswerData0" Correct="false"><Value>Other</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="true"><Value>sub</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="false"><Value>Colleague</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="true"><Value>sub</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="false"><Value>Colleague</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="false"><Value>man</Value></Input></AnswerData>
<AnswerData><Input Name="AnswerData0" Correct="false"><Value>Colleague</Value></Input></AnswerData>
任何人都可以提供见解或注意到我错过的 XML 中的某些内容。