Operand data type varchar is invalid for sum operator.

Analyst_SQL 3,576 Reputation points
2021-06-04T16:21:46.697+00:00

i am facing error on below line ,want comma in value ( 48,950.00)

Operand data type varchar is invalid for sum operator.

sum ( CONVERT(Varchar(50), Cast(tn.Debit as money),1))

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

Accepted answer
  1. Hafeez Uddin 296 Reputation points
    2021-06-04T17:20:38.593+00:00

    SUM can be used with numeric columns only. Null values are ignored.

    Try this
    CONVERT(Varchar(50), sum ( Cast(tn.Debit as money)),1))

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Cooper 8,486 Reputation points
    2021-06-04T17:45:01.63+00:00

    Use the FORMAT function, for example
    Create Table #T(Debit float);
    Insert #T(Debit) Values (40000), (8950);
    Select Format(Sum(Debit), 'N', 'en-us') From #T;
    Tom

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.