我有以下查詢,真正殺死性能,並想知道什麼替代他們是一個XML閱讀器子查詢。這個查詢的目的是用一些html代碼導出數據。表值函數[XML讀取器]非常慢 - 替代方法?
表數據的一個例子如下。
p_s_id | p_c_id | notes
-----------------------
1 | 1 | this note is really long.
2 | 1 | This is fun.
3 | null | long note here
4 | 2 | this is not fun
5 | 2 | this is not fun
6 | 3 | long note here
我想採取所有具有相同p_c_id的不同音符並將它們連接在一起,如下所示。
可以提供任何其他信息,以便隨時發表評論。
select distinct
p_c_id
,'<br/><br/>'+(select distinct '• ' +cast(note as nvarchar(max)) + ' <br/> '
from dbo.spec_notes_join m2
where m.p_c_id = m2.p_c_id
and isnull(note,'') <> ''
for xml path(''), type).value('.[1]', 'nvarchar(max)') as notes_spec
from dbo.spec_notes_join m
所以出口將如下所示:
p_c_id | notes
--------------
1 | <br/><br/> • this note is really long. <br/> &bull This is fun <br/>
2 | <br/><br/> • This is not fun. <br/>
3 | <br/><br/> • long note here. <br/>
表現要好得多。 –
CLR是迄今爲止最好的選擇。對不起,我沒有澄清過。 –