看MSND好长
CREATE TABLE XMLTable
(
    ID int primary key,
    Data xml,
)

INSERT INTO XMLTable (ID, Data) Values (1'<entity><id>1</id><name>name</name></entity>')

Select Data.query('/entity/name/text()')
FROM XMLTable WHERE Data.value('(/entity/id)[1]''int'= 1

-- Perform the same function

Select Data.value('(/entity/name/text())[1]''nvarchar(max)')
FROM XMLTable WHERE Data.value('(/entity/id)[1]''int'= 1

-- Much faster
Select Data.value('(/entity/name/text())[1]''nvarchar(max)')
FROM XMLTable WHERE Data.exist('/entity/id/text()="1"'= 1

-- The grammar is so ugly.
Update XMLTable Set Data.modify('replace value of (/entity/name/text())[1] with "UpdatedName"')

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-09-08
  • 2021-06-24
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2022-02-20
  • 2021-12-25
  • 2021-08-09
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
相关资源
相似解决方案