在C#中运行此XML SQL时发生错误。缺什么?它在SQL Server管理工作室中运行良好,但在c#中没有。
protected DataTable ServiceCodes(string orderColumn = default(string), bool orderAscending = true)
{
string sql = @" SELECT DISTINCT(Split.a.value('.', 'VARCHAR(100)')) AS Data
FROM
(
SELECT CAST('<M>' + REPLACE(Text09, ',', '</M><M>') + '</M>' AS XML) AS Data
FROM Assets
WHERE Category = 'Service'
) AS A CROSS APPLY Data.nodes ('/M') AS Split(a) ORDER BY Data";
return DatabaseConnection.ExecuteDataTable(sql, 120000);
}
答案 0 :(得分:4)
我认为您Text09
列中有一些特殊字符。试试这个:
SELECT DISTINCT(Split.a.value('.', 'VARCHAR(100)')) AS Data
FROM
(
SELECT CAST('<M>' + replace((select Text09 + '' for xml path('')), ',', '</M><M>') + '</M>' AS XML) AS Data
FROM Assets
WHERE Category = 'Service'
) AS A CROSS APPLY Data.nodes ('/M') AS Split(a) ORDER BY Data