• Here's another method.

    DECLARE @StartVarchar(5) = '07:00',

    @EndVarchar(5) = '05:59'

    SELECTCASE

    WHEN REPLACE(@Start, ':', '') < REPLACE(@End, ':','')

    THEN DATEDIFF(HH, CAST('1900-01-01 '+ @Start AS SmallDateTime), CAST('1900-01-01 ' + @End AS SmallDateTime)) + 1

    WHEN REPLACE(@Start, ':', '') > REPLACE(@End, ':','')

    THEN DATEDIFF(HH, CAST('1900-01-01 '+ @Start AS SmallDateTime), CAST('1900-01-02 ' + @End AS SmallDateTime)) + 1

    END

    I don't know if you want the difference in minutes or hours, but I assumed hours. Other wise change HH to MI in the DATEDIFFs and remove the +1's.



    For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.[/url]

    "Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort