【问题标题】:SQL Server select XML node by user define attribute valueSQL Server 通过用户定义属性值选择 XML 节点
【发布时间】:2019-02-02 05:49:02
【问题描述】:
如何通过用户定义的属性值获取xml节点
我想用@pagenumber_替换查询中的2
Declare @pagenumber_ varchar(max);
Set @pagenumber_ = '2';
Select applicationdata.query('(/applicationdata/page[@number="2"])[1]')
From Applications
【问题讨论】:
标签:
sql-server
xml
sql-server-2012
attributes
sqlxml
【解决方案1】:
试试这个:
CREATE TABLE #Applications
(
applicationdata XML
);
INSERT INTO #Applications (applicationdata)
VALUES ('<applicationdata><page number="1">page1</page><page number="2">page2</page></applicationdata>')
DECLARE @pagenumber_ VARCHAR(MAX);
SET @pagenumber_ = '2';
SELECT applicationdata.query('(/applicationdata/page[@number=sql:variable("@pagenumber_")])[1]')
FROM #Applications
DROP TABLE #Applications