Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 是否读取存储在SQL Server中的具有文本数据类型的XML文档?_Sql Server 2008 - Fatal编程技术网

Sql server 2008 是否读取存储在SQL Server中的具有文本数据类型的XML文档?

Sql server 2008 是否读取存储在SQL Server中的具有文本数据类型的XML文档?,sql-server-2008,Sql Server 2008,这是一个XML存储在SQL Server表列中的示例。 就像我有10多列一样,这里我需要选择最后插入的4列 <Section xml:space="aligned" Paste="False" xmlns="http://schemas.microsoft.com"> <Para FontSize="11" FontWeight="Normal" FontStyle="Normal" TextAlignment="Left"> <Run Text="this is

这是一个XML存储在SQL Server表列中的示例。 就像我有10多列一样,这里我需要选择最后插入的4列

<Section xml:space="aligned" Paste="False" xmlns="http://schemas.microsoft.com">
<Para FontSize="11" FontWeight="Normal" FontStyle="Normal" TextAlignment="Left">
<Run Text="this is the data to be select from here" />
</Para>
</Section>
我看过以前使用过的博客,但这是针对xml数据类型的

SELECT TOP 5
    ID,
    XmlContent.value('(/Section/Para/Data/@Text)[1]', 'varchar(200)')
FROM dbo.YourTableName
ORDER BY CreatedDate DESC
但我需要的xml数据存储在文本数据类型请建议谢谢

以前的博客数据获取为空

DECLARE @xmltbl TABLE (ID INT, XmlData XML)

INSERT INTO @xmltbl(ID, XmlData) 
VALUES(1, '<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run Text="Jubilee Financial Products is one of Europe’s largest structured product providers, working with 30 of the worlds’ largest banks. Jubilee is regulated in Ireland under MIFID and all products are regulated." />
</Paragraph></Section>'), 
(2, '<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run Text="Jubilee Financial Products is one of Europe’s largest structured product providers, working with 30 of the worlds’ largest banks. Jubilee is regulated in Ireland under MIFID and all products are regulated." />
</Paragraph></Section> ');

;WITH XMLNAMESPACES(DEFAULT 'xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation')
SELECT 
    ID,
    DataText = XmlData.value('(/Section/Paragraph/Run/@Text)[1]', 'varchar(200)')
FROM @xmltbl 
DECLARE@xmltbl表(ID INT,XmlData XML)
插入@xmltbl(ID,XmlData)
值(1,'
'), 
(2, '
');
;使用XMLNAMESPACES(默认值“xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation')
挑选
身份证件
DataText=XmlData.value('(/Section/paragration/Run/@Text)[1],'varchar(200)'
来自@xmltbl

最好的方法是将您的列转换为数据类型
XML
,因为
TEXT
已失效,不应再使用:

ALTER TABLE dbo.YourTableName
   ALTER COLUMN XmlContent XML 
如果无法执行此操作,则每次查询时都需要将
文本
转换为
XML

SELECT 
    CAST(XmlContent AS XML).value('declare namespace ns="http://schemas.microsoft.com";(/ns:Section/ns:Para/ns:Run/@Text)[1]', 'varchar(200)')
FROM dbo.YourTableHere

Thnaks Marc_s我不能做我现在就试试你的答案Marc_s我正在获取ID,但我正在获取CAST(XmlContent作为XML)。value(“(/Section/Para/Data/@Text)[1]”,varchar(200)”)null VAUE我犯了什么错误请让我知道谢谢Marc_你帮了我很多,但你的回答上面我是addind它也给了null你能检查一下吗?添加了一些小的修改,我不能改变任何东西。请检查前一个,如果它对我来说足够了,这只是你的答案
ALTER TABLE dbo.YourTableName
   ALTER COLUMN XmlContent XML 
SELECT 
    CAST(XmlContent AS XML).value('declare namespace ns="http://schemas.microsoft.com";(/ns:Section/ns:Para/ns:Run/@Text)[1]', 'varchar(200)')
FROM dbo.YourTableHere