沒有什麼特別有CDATA節。
declare @xml xml =
'<productDetailsDescription>
<![CDATA[Candidates for this exam are professionals who typically pursue careers as database administrators, database developers, or business intelligence developers. Additionally, they can be people who do not work with Microsoft SQL Server as a part of their primary job functions but who want to show their breadth of technology experience, such as developers, systems administrators, and others. ]]>
</productDetailsDescription>
<productImage>/m/967558/40.jpg</productImage>
<application>Slmnoasp</application>'
select @xml.value('/productDetailsDescription[1]', 'nvarchar(225)')
它也處理混合值。
declare @xml xml =
'<root>123<![CDATA[ABD]]>456</root>'
select @xml.value('/root[1]', 'nvarchar(10)')
結果:
(No column name)
123ABD456
編輯
從表而不是用強制轉換爲XML的變量:
select cast(xml as xml).value('/productDetailsDescription[1]', 'nvarchar(max)') as productDetailsDescription
from YourTable
這裏試試:http://data.stackexchange.com/stackoverflow/q/108293/
編輯2
您需要在查詢中指定節點名稱。您還必須決定是否應該在同一列中使用不同的節點,或者應該使用不同的列。下面我向你展示如何做到這一點。
declare @T table(xml nvarchar(max))
insert into @T values
('<productDetailsDescription>
<![CDATA[Candidates for this exam are professionals who typically pursue careers as database administrators, database developers, or business intelligence developers. Additionally, they can be people who do not work with Microsoft SQL Server as a part of their primary job functions but who want to show their breadth of technology experience, such as developers, systems administrators, and others. ]]>
</productDetailsDescription>
<productImage>/m/967558/40.jpg</productImage>
<application>Slmnoasp</application>')
insert into @T values
('<detailDescription>
<![CDATA[Candidates for this exam are professionals who typically pursue careers as database administrators, database developers, or business intelligence developers. Additionally, they can be people who do not work with Microsoft SQL Server as a part of their primary job functions but who want to show their breadth of technology experience, such as developers, systems administrators, and others. ]]>
</detailDescription>
<productImage>/m/967558/40.jpg</productImage>
<application>Slmnoasp</application>')
-- Get detailDescription in a column of its own
select
cast(xml as xml).value('/productDetailsDescription[1]', 'nvarchar(max)') as productDetailsDescription,
cast(xml as xml).value('/detailDescription[1]', 'nvarchar(max)') as detailDescription
from @T
-- Get detailDescription in the same column as productDetailsDescription
select
cast(xml as xml).value('/*[local-name()=("productDetailsDescription","detailDescription")][1]', 'nvarchar(max)') as detailDescription
from @T
您能否提供一些示例XML數據,以顯示您的XML看起來像什麼以及您想要的輸出應該是什麼。 –