Calculating "Sum" of Numeric values in Varchar fld
|
Classic ASP BasicsFor beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Calculating "Sum" of Numeric values in Varchar fld
Hello!
I have a Varchar field, in which has only numeric values. I want to calculate the sum of using the sql query.
Right now the query I"m using is:
SSQL = "select SUM(AMOUNT) AS VARAMOUNT from ORDER"
The above sql statement gives the following error:
Cannot calculate SUM of varchar field
itHighway
Your error explains it clearly:
;;;Cannot calculate SUM of varchar field
means what it says. Does this field need to be a varchar? varchars are stored as strings. Two options come to mind:
1..re think you data base design changing this field to some type of integer
2..Get the values, convert to integer...
What if someone types 'one' or 'two' etc into this field? your sum result could be incorrect. There are more reasons why a field that is to be summed should be some sort of integer. Anyway, glad you sorted it.