• Mark-101232 (5/15/2013)


    SELECT AdDate, AdTime, FK_StationId, CAST(rank() over(partition by fk_stationid order by addate,adtime) AS VARCHAR(10)) + ' of ' +

    CAST(count(*) over(partition by fk_stationid) AS VARCHAR(10)) as Position

    FROM dbo.TestTable

    GROUP BY AdDate, AdTime, FK_StationId

    HAVING (AdDate = CONVERT(DATETIME, '2013-04-01 00:00:00', 102))

    This is the coolest thing I've seen SQL do in weeks. Thanks.