2

I'm trying to update added column "XML_File" for all(~50 000) rows with each rows XML file, so solution with CASE, WHEN, THEN is not reasonable. For test purposes I'm using AdventureWorks2012. Code I ran to create and save XML for BusinessEntityID = 1:

UPDATE [Person].[Password]
   SET [XML_File] = (SELECT [BusinessEntityID]
      ,[PasswordHash]
      ,[PasswordSalt]
      ,[rowguid]
      ,[ModifiedDate]
      ,[XML_File]
  FROM [Person].[Password]
WHERE BusinessEntityID = 1
FOR XML PATH('Summary'))
WHERE BusinessEntityID = 1

Table view: enter image description here

Created XML:

<Summary>
  <BusinessEntityID>1</BusinessEntityID>
  <PasswordHash>pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM</PasswordHash>
  <PasswordSalt>bE3XiWw=</PasswordSalt>
  <rowguid>329EACBE-C883-4F48-B8B6-17AA4627EFFF</rowguid>
  <ModifiedDate>2003-02-08T00:00:00</ModifiedDate>
</Summary>

So, is there a way of achieving my goal with sql query?

1 Answer 1

1
UPDATE p
SET [XML_File] = (
    SELECT [BusinessEntityID]
         , [PasswordHash]
         , [PasswordSalt]
         , [rowguid]
         , [ModifiedDate]
    FOR XML PATH ('Summary')
)
FROM [Person].[Password] p
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.