Error converting data type varchar to numeric.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • voroojak
    New Member
    • Feb 2007
    • 92

    #1

    Error converting data type varchar to numeric.

    HI
    i have a very big problem.
    i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
    what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
    this is my code


    case when Revenue='A' then Sum(total_amt) else ' ' end as A

    but it is giving me and error Error converting data type varchar to numeric.
    please help
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by voroojak
    HI
    i have a very big problem.
    i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
    what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
    this is my code


    case when Revenue='A' then Sum(total_amt) else ' ' end as A

    but it is giving me and error Error converting data type varchar to numeric.
    please help

    first, why the error.

    because your case statement said when revenue = 'A' return the sum of total_amt else return blank...the case statement should return (the then part and the else part) the same datatype or at least can be converted to the same datatype.

    try ....else sum(0) end as A, ...or .....else 0 end as A

    Comment

    Working...