Solved

Sum of a VarChar Field

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

770 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