• I took out your variable for my testing so you will need to add it back in...  Anyway, I think this does what you need - eventhough it is extremely ugly.  I would keep looking for a better way to do it.  I don't think this will be very effecient.

    SELECT r.year, r.qtr, r.industry_code

     FROM rpt_calc_data r INNER JOIN

       (select year, qtr, min(empl) as empl

        from rpt_calc_data r

        where r.nd = 0

        group by year, qtr) AS Z ON r.year = z.year and r.qtr = z.qtr and r.empl = z.empl

    WHERE r.nd = 0

    AND NOT EXISTS

    (SELECT * FROM (

    select r.year, r.qtr,  v1.empl, min(industry_code) industry_code

    FROM

    (

    select year, qtr, min(empl) as empl, count(*) as count

    from rpt_calc_data r

    where r.nd = 0

    group by year, qtr

    having count(*)>1

    ) v1

    INNER JOIN rpt_calc_data r

    ON r.year = v1.year and r.qtr = v1.qtr and r.empl = v1.empl

    WHERE r.nd = 0

    GROUP BY r.year, r.qtr, v1.empl

    )  vt WHERE vt.empl=r.empl)

    UNION ALL

    select year, qtr, industry_code FROM

    (

    select r.year, r.qtr,  v1.empl, min(industry_code) industry_code

    FROM

    (

    select year, qtr, min(empl) as empl, count(*) as count

    from rpt_calc_data r

    where r.nd = 0

    group by year, qtr

    having count(*)>1

    ) v1

    INNER JOIN rpt_calc_data r

    ON r.year = v1.year and r.qtr = v1.qtr and r.empl = v1.empl

    WHERE r.nd = 0

    GROUP BY r.year, r.qtr, v1.empl

    ) vt