Link to home
Start Free TrialLog in
Avatar of E-Risk
E-Risk

asked on

Sum of a VarChar Field

How to I perform a sum on a varchar field that always contains numeric content?
ASKER CERTIFIED SOLUTION
Avatar of DireOrbAnt
DireOrbAnt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aneesh
SELECT SUM(CAST (varcharColumn as integer )) -- you can cast it as integer or numeric (10,2) depending on the values stored
WHERE ISNUMERIC(varcharColumn) =1
Now , if it stores a numeric field always, they ehy you keep it as a varchar column ?
Avatar of Raynard7
Raynard7

select sum(cast(fieldName as int)) from tableA

Will find the sum (assumin that the numbers you have are integers)