• Mark-101232 (9/4/2012)


    See if this helps

    select

    MainLock.Process.value('@id', 'varchar(100)') AS LockID,

    OwnerList.Owner.value('@id', 'varchar(200)') AS ProcessId,

    MainLock.Process.value('local-name(.)','varchar(100)') AS LockType,

    MainLock.Process.value('@objectname','sysname') AS ObjectName,

    OwnerList.Owner.value('@mode', 'varchar(10)') AS LockMode

    from @DeadlockGraph.nodes('/deadlock-list/deadlock/resource-list') AS Lock(list)

    OUTER APPLY Lock.list.nodes('(pagelock,keylock,ridlock,objectlock,exchangeEvent)') AS MainLock(Process)

    OUTER APPLY MainLock.Process.nodes('owner-list/owner') AS OwnerList(Owner)

    ;

    Mark,

    This is so seriously cool. I didn't know that you could specify the various elements like that, or retrieve back the node name. And best of all... it works!

    Time to go revamp my script yet again.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2