Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 sql server中的Xml列属性操作_Sql Server - Fatal编程技术网

Sql server sql server中的Xml列属性操作

Sql server sql server中的Xml列属性操作,sql-server,Sql Server,我的数据库中有一个名为User的表。其中有一个名为XmlText的xml列,它包含许多属性 <userDetails> <MobileVerified>True</MobileVerified> <EmailVerified>True</EmailVerified> <IPAddress>122.160.65.232</IPAddress> <Gender>Male</Gen

我的数据库中有一个名为User的表。其中有一个名为XmlText的xml列,它包含许多属性

  <userDetails>
  <MobileVerified>True</MobileVerified>
  <EmailVerified>True</EmailVerified>
  <IPAddress>122.160.65.232</IPAddress>
  <Gender>Male</Gender>
  <DateOfBirth>1970-03-22T00:00:00</DateOfBirth>
  <DealingInProperties>residential_apartment_flat</DealingInProperties>
  <DealingInProperties>residential_villa_bungalow</DealingInProperties>
  <DealingInProperties>residential_farm_house</DealingInProperties>
</userDetails>

if ('residential_villa_bungalow') exists
(
if ('residential_apartment_flat') exists
    remove the 'residential_villa_bungalow' node as there must be only one 'residential_apartment_flat' node
else
    update 'residential_villa_bungalow' into 'residential_apartment_flat'
)
-- Delete bungalow where already exist a flat
update YourTable
set    XMLText.modify('delete /userDetails/DealingInProperties[. = "residential_villa_bungalow"] ')
where  XMLText.exist('/userDetails[DealingInProperties = "residential_apartment_flat"]') = 1 and
       XMLText.exist('/userDetails[DealingInProperties = "residential_villa_bungalow"]') = 1

-- Change value from bungalow to flat
update YourTable 
set    XMLText.modify('replace value of (/userDetails/DealingInProperties[. = "residential_villa_bungalow"]/text())[1] 
                       with "residential_apartment_flat"')
where  XMLText.exist('/userDetails[DealingInProperties = "residential_villa_bungalow"]') = 1