3

この XML SQL を C# で実行すると、エラーが発生します。何が欠けている?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);
}
4

1 に答える 1

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

見るsql fiddle demo

于 2013-08-28T09:11:23.800 に答える