Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sum of a VarChar Field

Posted on 2006-07-21
4
Medium Priority
?
2,490 Views
Last Modified: 2008-09-25
How to I perform a sum on a varchar field that always contains numeric content?
0
Comment
Question by:E-Risk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 500 total points
ID: 17158853
SUM(CAST(MyVarcharField AS INT))
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17158856
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
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17158859
Now , if it stores a numeric field always, they ehy you keep it as a varchar column ?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17158860
select sum(cast(fieldName as int)) from tableA

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

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question