How to add the numbers in T-SQL

  • Hello All,

    I need to add these numbers

    0,-77.21,4

    I want the output as -73.21.

    When I am using + operator it is just concatenating.

    Please assist.

    Thanks

  • if the datatype is vachar, then it will concatenate instead of addition.

    you'll most likely have to explicitly convert to decimal, or money:

    select convert(money,'77.41') + convert(money,'4')

    if this is a column of data, you should consider fixing the datatypes to be numeric instead of varchars.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks so much. I got it

  • it will allow to do the addition if the data type is numeric. if column data type is char it will just contaminate.

    java[/url]

  • salum (12/19/2011)


    it will allow to do the addition if the data type is numeric. if column data type is char it will just contaminate.

    Only if the table contains biological wastes. 😛

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

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

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