如何使用SQL Server

时间:2016-07-27 06:09:35

标签: sql-server sql-server-2008

任务-1:请帮我查询或存储过程以分割逗号值。

任务-2:使用ROW1数据可以做什么最好?

Column-A Column-B

  1. Vildagliptin,Exenatide,5075,,4085,

  2. Canakinumab,3743,

  3. Canagliflozin,3742,

  4. Canakinumab,3743,

1 个答案:

答案 0 :(得分:0)

尝试这样,(不使用功能)

SELECT [Column-A],
LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS [Column-B]
FROM
(
SELECT [Column-A],CAST('<XMLRoot><RowData>' + REPLACE([Column-B],',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
FROM   <YourTable>
)t
CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)