4

Is it possible to use XML.modify within a case statement like this or would this have to be 2 separate update statements?

UPDATE s
SET     
   CASE WHEN [XMLData] IS NOT NULL THEN [XMLData].modify('delete //invoice/account/contactinformation') END,
   CASE WHEN [SummaryXMLData] IS NOT NULL THEN [SummaryXMLData].modify('delete //invoice/account/contactinformation') END 
FROM   
    ITS_CSC.[Statement].[StatementSummary] s    

SQL Server throws this error:

Msg 156, Level 15, State 1, Line 34
Incorrect syntax near the keyword 'CASE'.

NB: Calling the modify method directly on a NULL value fails with the following message hence need to check for NULLs

Mutator 'modify()' on 'column name' cannot be called on a null value.

1 Answer 1

3

It is incorrect syntax. You could use 2 separate statements instead:

UPDATE ITS_CSC.[Statement].[StatementSummary]
SET  [XMLData].modify('delete //invoice/account/contactinformation') 
WHERE [XMLData] IS NOT NULL;

UPDATE ITS_CSC.[Statement].[StatementSummary]
SET [SummaryXMLData].modify('delete //invoice/account/contactinformation')
WHERE [SummaryXMLData] IS NOT NULL;
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.