Help on SQL query

  • I have a database in which I pull the following events from a query:

    select

    loginname,

    servername,

    databasename,

    starttime

    eventclass,

    eventname

    from dbo.audit_table

    where eventclass = 20

    How can I modify my query to only pull the events for the past half hour?

    Thx,

    Jeff

  • add this to your where clause :

    AND starttime >= DATEADD(n, -30, GETDATE())

    Of course it might also make good sense to to check on the endtime instead...

  • We need the DDL code before we can comment really but it should be reasonably straight forward if your 'starttime' is a DateTime datatype.

    Something like this should do it:

    WHERE starttime > DATEADD(mi,-30, GETDATE())



    MCSE: Data Platform
    MCSE: Business Intelligence
    Follow me on Twitter: @WazzTheBadger
    LinkedIn Profile: Simon Osborne

  • Thx for the syntax! Greatly appreciated.

    Unfortunately, the end date is not a column I can pull from so start date will have to suffice for now.

    Jeff

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply