Solved

Sum of a VarChar Field

Posted on 2006-07-21
4
2,487 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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

636 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