Sum CHAR DataType in SQL

How can I Sum a CHAR DataType in SQL????????
The Data that I have in my table is like this
Field1
---------
1400.00
1521.00
1523.35
.
.
.
Even it looks like number it is not it was specified as CHAR in the Tbale's Dising
amedexittAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MartinCMSConnect With a Mentor Commented:
try...

select sum(convert(numeric(8,2),Field1))
from yourTable
0
 
RaisinJCommented:
Convert(INT,@Field)

Select
    Sum(Convert(INT,Field1)) As Field1
From
    Table!

The only time this will give you a problem is if there are non numeric charaters in the field...
0
 
RaisinJConnect With a Mentor Commented:
Sorry,

Noticed your Fields has decimals... In that case, you'll receive and error when converting to INT, you want to Convert to Decimal...

Convert(Decimal(10,2),Field)

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
waelothmanCommented:
select sum(cast (fieldname as real)) from tablename
0
 
AntonGCommented:
although the above comments are pretty much correct.... I would rather do the conversion to a float...

i.e. SELECT SUM(CONVERT(float, colname)) FROM tablename
0
 
sukumar_diyaCommented:
You can try this also

select sum(cast(columnname as float)) from tablename
0
 
svidCommented:
To be on the safer side you may want to add

where isnumeric(Field1) = 1 to the select statement so you don't get a syntax error if there are non-numeric values
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.