Solved

Sum of a VarChar Field

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 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

18 Experts available now in Live!

Get 1:1 Help Now