• I recently had cause to revisit this fine article... well done, Adam. Great for neophytes and alumni alike.

    As a side bar, here's the code I ended up using which could actually be turned into an iTVF...

    SELECT trc.LoginName,

    -- trc.LoginSID,

    trc.SPID,

    trc.IsSystem,

    trc.HostName,

    trc.ApplicationName,

    trc.ServerName,

    trc.DatabaseName,

    trc.ObjectName,

    evt.Category_ID,

    CategoryName = cat.name,

    trc.TextData,

    trc.StartTime,

    trc.EventClass,

    trc.EventSubClass,

    EventName = evt.name

    FROM FN_TRACE_GETTABLE( (

    SELECT CAST([Value] AS NVARCHAR(4000)) --Drive, path, and filename of trace file

    FROM FN_TRACE_GETINFO(0) --0 = Current Server

    WHERE [Property] = 2 --2 = Trace File Path

    )

    ,0) trc --0 = Latest default trace file

    INNER JOIN sys.Trace_Events evt ON eventclass = trace_event_id

    INNER JOIN sys.Trace_Categories cat ON evt.category_id = cat.category_id

    WHERE trc.DatabaseName = 'somedatabasenamehere'

    AND trc.ObjectName = 'somesqlserverobjectnamehere'

    ;

    Heh... and, no... I don't code for things to work on case sensitive servers. 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)