Multiple delete in xml column



In the paper, "Introduction to XQuery in SQL Server 2005,
http://msdn2.microsoft.com/en-us/library/ms345122.aspx,
it gives an example below of deleting one element and says it could be
modified to do multiple elements.

What is the best approach to do this when the elements to be deleted
are based on a column in another table?

I'm doing this in a trigger, but code below only evaluates sql:column
for first row in Deleted table.

MSDN says that sql:column is not supported with JOIN, must use APPLY.
But I can't see how to do that either.

UPDATE SecurityAccount
SET SecuredObjectPermissions.modify('
delete (/SecuredObjectPermissions/
SecuredObjectPermission[SecuredObject=sql:column("d.SecuredObjectID")])
')
FROM DELETED d WHERE SecurityAccountID = d.UserAccountID and
IsAccountDeleted = 0

Thanks.

Excerpt from MSDN article:
-------------------------------------------------------------------------------------
Example: Deleting a skill

The following example illustrates the use of the delete keyword to
delete a skill for a specified candidate.

The following stored procedure is written based on the assumption that
the user will pass a string value of one skill as the second argument
to the stored procedure. This stored procedure can be modified to
accept an XML fragment that contains one or more skill elements,
thereby allowing the user to delete multiple skill nodes with a single
invocation of the stored procedure.

/* Stored procedure to delete a specified skill element for a
candidate */
CREATE PROCEDURE [DeleteSkillInfo]
@JobCandidateID [int],
@Skill [varchar](200)
AS
BEGIN
SET NOCOUNT ON;

UPDATE [CandidateInfoXMLDataType]
SET Resume.modify('
delete (/JobCandidate/Skills/Skill[.=sql:variable("@Skill")])
')
WHERE JobCandidateID = @JobCandidateID
END

This stored procedure can easily be modified to accept an XML fragment
which contains one or more skill elements thereby allowing the user to
delete multiple skill nodes with a single invocation of stored
procedure.
.



Relevant Pages

  • RE: Looping through XML document
    ... Introduce a looping for the varying skill values - I am not sure using what ... layout) skill level to SQL stored procedure. ... > able to update the employee table by passing the top level nodes to the add ...
    (microsoft.public.biztalk.general)
  • RE: Looping through XML document
    ... The SQL calls is simply a schema with the parameters (in this case Employee, ... Skill) which is sent to a port in the Orchistration. ... > layout) skill level to SQL stored procedure. ...
    (microsoft.public.biztalk.general)

Loading