• smitty-1088185 (11/22/2014)


    How can I find the tables

    below that failed and were never successful for the same day? Some tables may succeed or fail

    more than once on the same day.

    Now how do I find out if those two entries Table1 and Table3 were later successful for 11/22/2014?

    This is A way of doing this.

    ** NOTES **

    This is not the most efficient way to do this but should be enough to get you pointed in the right direction.

    This works for the dataset provided.

    See how the DDL is formated for easy consumption for future posts!!

    declare @t1 table

    (

    Table_Name varchar(20)

    ,Import_Status varchar(7)

    ,Start_Time datetime

    )

    Insert @t1 (Table_Name, Import_Status, Start_Time) VALUES

    ('Table1', 'fail', '2014-11-22 02:05:00.000')

    ,('Table1', 'success', '2014-11-22 16:51:00.000')

    ,('Table2', 'success', '2014-11-22 05:59:00.000')

    ,('Table2', 'success', '2014-11-23 05:51:00.000')

    ,('Table3', 'fail', '2014-11-22 05:30:00.000')

    ,('Table3', 'success', '2014-11-23 06:50:00.000')

    ,('Table1', 'success', '2014-11-22 18:51:00.000');

    select Table_Name, CAST(start_time as DATE) RunDate

    ,SUM(case when import_status = 'success' then 1 else 0 end) successRuns

    ,SUM(case when import_status = 'fail' then 1 else 0 end) failedRuns

    from @t1

    group by Table_Name, cast(Start_Time as date)

    order by Table_Name

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/