subtracting 2 time data types error

  • I need a simple sql statement with a case to determine whether 2 times need to be added or subtracted

    the case statement i have works... but sql wont allow me to subtract or add the 2 timespan datatypes.

    the case statement reads

    ok the statement reads:

    CASE WHEN dbo.Races.rSealed = 0 THEN (dbo.Results.rTime - dbo.Results.rHandicap) ELSE (dbo.Results.rTime + dbo.Results.rHandicap)

    END AS 'Actual Time'

    the data types are both time(4)

    the error is:

    Operand data type time is invalid for subtract operator.

    ive been searching everywhere...even guidance on what to read would be appreciated

  • Michael Artz (12/15/2008)


    I need a simple sql statement with a case to determine whether 2 times need to be added or subtracted

    the case statement i have works... but sql wont allow me to subtract or add the 2 timespan datatypes.

    the case statement reads

    ok the statement reads:

    CASE WHEN dbo.Races.rSealed = 0 THEN (dbo.Results.rTime - dbo.Results.rHandicap) ELSE (dbo.Results.rTime + dbo.Results.rHandicap)

    END AS 'Actual Time'

    the data types are both time(4)

    the error is:

    Operand data type time is invalid for subtract operator.

    ive been searching everywhere...even guidance on what to read would be appreciated

    Please read the article below in my signature block regarding how to ask for help. What would really help here is the DDL for the table, some sample data for the table, expected results based on the sample data, and the complete code you are currently using. The article below actually tells you step by step how to put all of this together for posting so that you get the best answer in response.

  • Duplicate post. Please post answers here

  • Are you sure it shouldn't be posted here instead of there? One post is in SQL Server 2005 and the other is SQL Server 2008. In the other post, I asked what version of SQL he is using.

  • Lynn Pettis (12/15/2008)


    Are you sure it shouldn't be posted here instead of there? One post is in SQL Server 2005 and the other is SQL Server 2008. In the other post, I asked what version of SQL he is using.

    I don't know, I just gave an answer in the other one and didn't want to see it repeated. He does mention the timespan data type which isn't a data type in 2005.

  • Good thing I didn't tell people to post here instead in the other thread. At this point, I just want to know what version of SQL is being used.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply