• Steve-0 (5/5/2014)


    Hi Everyone thanks for the replies.

    For the first 2, I'm not using static dates as per your queries.

    Scott, your query is just casting values for actual field values. OPENDATE and ASSGNDATE are actual fields in a task table. When I run that query I get 3 returned records based solely on the SELECT GETDATE.

    The output is based on the current time:

    ASSNDATE OPENDATE Date_Diff

    2014-05-05 09:29:30.8332014-05-05 09:38:30.8330:09

    2014-05-05 06:22:30.8332014-05-05 09:38:30.8333:16

    2014-05-04 07:46:30.8332014-05-05 09:38:30.83325:52

    I need to do this on every record in the table (minus anything that's not being worked on). Suggestions?

    That was just to provide sample data. Naturally you should replace:

    FROM (

    SELECT GETDATE() AS OPENDATE, DATEADD(MINUTE, -9, GETDATE()) AS ASSNDATE UNION ALL -- lt 60 mins

    SELECT GETDATE(), DATEADD(MINUTE, -196, GETDATE()) UNION ALL -- gt 60 mins, lt 24 hrs

    SELECT GETDATE(), DATEADD(MINUTE, -(24*60+112), GETDATE()) -- gt 24 hrs

    ) AS test_data

    with your own table name, like

    FROM dbo.your_table_name

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.