正在 SQL 服务器中提取 XML 字段
Extracting XML field in SQL Server
我在 MIWOD
table 中有 fldxml
列,其中包含多种类型的数据。如何显示 [fldxml]
列值,如下所示?
Routing Drawing
1 C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf
这是 [fldxml]
的样子
<fields>
<field1>1</field1>
<field2>C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf</field2>
</fields>
我想要这样的东西
Routing Drawing:
1 C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf
我尝试使用以下
SELECT
MIWOD.fldXml('(field1/text())[1]', 'varchar(50)') as Routing,
MIWOD.fldXml('(field1/text())[1]', 'varchar(50)') as Routing
FROM
[MISAMPCO].[dbo].[MIWOD]
但是我得到以下错误
Cannot find either column "MIWOD" or the user-defined function or aggregate "MIWOD.fldXml", or the name is ambiguous.
DECLARE @stuff xml
SET @stuff = '<fields><field1>1</field1><field2>C:\Users\Kinfe\Documents\LETTUCE_WHEEL.pdf</field2></fields>'
SELECT
Child.value('field1[1]', 'int') [**Routing:**],
Child.value('field2[1]', 'nvarchar(max)') [**Drawing:**]
FROM
@stuff.nodes('fields[1]') as N(Child)
我在 MIWOD
table 中有 fldxml
列,其中包含多种类型的数据。如何显示 [fldxml]
列值,如下所示?
Routing Drawing
1 C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf
这是 [fldxml]
的样子
<fields>
<field1>1</field1>
<field2>C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf</field2>
</fields>
我想要这样的东西
Routing Drawing:
1 C:\Users\XXX\Documents\LETTUCE_WHEEL.pdf
我尝试使用以下
SELECT
MIWOD.fldXml('(field1/text())[1]', 'varchar(50)') as Routing,
MIWOD.fldXml('(field1/text())[1]', 'varchar(50)') as Routing
FROM
[MISAMPCO].[dbo].[MIWOD]
但是我得到以下错误
Cannot find either column "MIWOD" or the user-defined function or aggregate "MIWOD.fldXml", or the name is ambiguous.
DECLARE @stuff xml
SET @stuff = '<fields><field1>1</field1><field2>C:\Users\Kinfe\Documents\LETTUCE_WHEEL.pdf</field2></fields>'
SELECT
Child.value('field1[1]', 'int') [**Routing:**],
Child.value('field2[1]', 'nvarchar(max)') [**Drawing:**]
FROM
@stuff.nodes('fields[1]') as N(Child)