• 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,

    FYI: I changed the one line to:

    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('*') AS MainLock(Process)

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

    ;

    so that it will handle any node at that level. Looking great, and now it will handle the threadpool and resourceWait locks.

    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