• Perhaps this is what you mean.

    WITH SampleData (date, HourType, hours, HourValue, status) AS(

    SELECT 'day1','m',1,1,'y'

    UNION ALL SELECT 'day1','m',2,1,'y'

    UNION ALL SELECT 'day1','m',3,1,'y'

    UNION ALL SELECT 'day1','a',4,0,'n'

    UNION ALL SELECT 'day1','a',5,0,'n'

    UNION ALL SELECT 'day1','a',6,0,'n'

    UNION ALL SELECT 'day2','m',1,1,'y'

    UNION ALL SELECT 'day2','m',2,1,'y'

    UNION ALL SELECT 'day2','m',3,1,'y'

    UNION ALL SELECT 'day2','a',4,0,'y'

    UNION ALL SELECT 'day2','a',5,1,'y'

    UNION ALL SELECT 'day2','a',6,1,'y'

    )

    SELECT *

    ,CASE (

    SELECT MAX(HourValue)

    FROM SampleData b

    WHERE a.date = b.date AND a.HourType = b.HourType

    ) WHEN 1 THEN 'y' ELSE 'n' END

    FROM SampleData a;


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St