• Erland Sommarskog (9/21/2013)


    You need a table of numbers, I have an explanation of this concept on

    http://www.sommarskog.se/arrays-in-sql-2005.html#tblnum (only read down to the header "An inline function".)

    Once you have this table, you can translate the numbers to half-hours with the dateadd function. Then you join against your table:

    ON halfhours.halfhour BETWEEN StartTime AND EndTime

    And then do a SELECT halfhour, COUNT(*) GROUP BY halfhour.

    Thanks for your help, but I still have problems,

    1.where can create inline function? In view? or where?

    2. If I have duplicate name in the table, may I group by name, halfhour ?

    Thanks a lot