Solved

Sum of a VarChar Field

Posted on 2006-07-21
4
2,477 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
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 125 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now