• If I understood your requirements, the following is what you'll need. Offhand about your test data, everything had an id of 1 before I modified it.

    Short form of what this does: Pivot the test data, check each value against the validation set, and return outliers. Only return each ID once in case of multiple failures.

    declare @Table1 table

    (id int,

    StartDt datetime,

    EndDt datetime)

    insert into @Table1

    select 1,'2009-11-28 00:00:00.000',''

    union all

    select 2,'2009-11-07 00:00:00.000','2009-11-27 00:00:00.000'

    union all

    select 3,'2009-07-01 00:00:00.000','2009-11-06 00:00:00.000'

    union all

    select 4,'2009-06-19 00:00:00.000','2009-06-30 00:00:00.000'

    select * from @Table1

    declare @Table2 table

    (id int,

    StartDt datetime,

    EndDt datetime)

    insert into @Table2

    select 1,'2008-11-05 00:00:00.000','2009-11-06 00:00:00.000'

    union all

    select 2,'2007-11-29 00:00:00.000','2008-11-04 00:00:00.000'

    union all

    select 3,'2007-09-04 00:00:00.000','2007-09-04 00:00:00.000'

    union all

    select 4,'2007-07-02 00:00:00.000','2007-07-12 00:00:00.000'

    union all

    select 5,'2006-09-05 00:00:00.000','2007-06-21 00:00:00.000'

    select * from @Table2

    ;WITH pivotedData AS

    (SELECT id, StartDt as TestDT

    FROM@Table1

    UNION ALL

    SELECT id, EndDt AS TestDT

    FROM@Table1

    )

    SELECT DISTINCT

    pd.ID

    FROM

    pivotedData AS pd

    LEFT JOIN

    @table2 AS t2

    ONpd.TestDT >= t2.StartDt

    AND pd.TestDt <= t2.EndDt

    WHERE

    t2.id IS NULL


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA