• You shouldn't be storing times as nvarchar. SQL Server has a time datatype (and plenty others datetime types).

    We also have the function DATEDIFF available so we don't have to reinvent the wheel to do time calculations. DATEDIFF can implicitly convert well formatted strings into an adequate data type. Just be sure to have the correct values or you'll find errors.

    Check the following example:

    DECLARE @Sample TABLE(

    OTIM nvarchar(8),

    ReportedTime nvarchar(5))

    INSERT INTO @Sample

    VALUES

    ( '12:34:34', '12:34'),

    ( '12:34:34', '13:34'),

    ( '12:34:34', '11:34'),

    ( '12:34:34', '12:00'),

    ( '12:34:34', '1:00')

    SELECT *,

    CAST(OTIM AS TIME) OTIM_As_Time,

    CAST(ReportedTime AS TIME) ReportedTime_As_Time,

    DATEDIFF(HH, OTIM, ReportedTime) Difference_In_Hours

    FROM @Sample

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2