• In that case, this should work nicely for you:

    DECLARE @Miview TABLE

    (Username VARCHAR(20), Start DATETIME, Activity VARCHAR(20))

    INSERT INTO @Miview

    SELECT 'Tom', '2012-09-07 12:00', 'Logon'

    UNION ALL SELECT 'Fred', '2012-09-07 12:01', 'Logon'

    UNION ALL SELECT 'Fred', '2012-09-07 12:02', 'Logon'

    UNION ALL SELECT 'Tom', '2012-09-05 12:00', 'Logon'

    UNION ALL SELECT 'Fred', '2012-09-05 12:01', 'Logon'

    UNION ALL SELECT 'Sam', '2012-09-05 12:02', 'Logon'

    UNION ALL SELECT 'Bob', '2012-09-05 12:03', 'Logon'

    DECLARE @Start DATE = '2012-09-04'

    ,@End DATE = '2012-09-08'

    ,@Days INT

    ;WITH Tally (n) AS (

    SELECT TOP(1+DATEDIFF(day, @Start, @End))

    ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1

    FROM sys.all_columns)

    SELECT [Date]=STUFF(

    REPLACE('/'+CONVERT(VARCHAR(5), Start, 101), '/0', '/')

    , 1, 1, '')

    ,UniqueLogins=COUNT(DISTINCT Username)

    FROM (

    SELECT UserName, Start=DATEADD(d, DATEDIFF(d, 0, Start), 0), Activity

    FROM @Miview

    WHERE Activity = 'Logon' AND Start >= @Start AND Start < DATEADD(day, 1, @End)

    UNION ALL

    SELECT NULL, DATEADD(day, n, @Start), 'Logon'

    FROM Tally) a

    GROUP BY Start

    ORDER BY Start


    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