Solved

convert to 0.00

Posted on 2010-11-11
9
289 Views
Last Modified: 2012-05-10
93.06  
93.01  
924,95
355.24  
355,96
355,41
2.245,82
2.074,95
2.034,95  
2,579.70
1.284,81  
1.284,81  
1.275,81  

want to find sum of this varchar column
there are
,
and
both
. and ,
large numbers

I would like to convert all to 0.00
0
Comment
Question by:rgb192
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Accepted Solution

by:
mkobrin earned 167 total points
ID: 34111178
sum(convert(tofloat, columnName))

Should do it for you or you can use a convert to decomal with the required settings as well.
0
 

Author Comment

by:rgb192
ID: 34111258
Msg 243, Level 16, State 1, Line 2
Type tofloat is not a defined system type.
0
 
LVL 7

Expert Comment

by:mkobrin
ID: 34111286
Sorry (Using C# syntax)

Try sum(convert(float, columnName))
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:rgb192
ID: 34111639
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34111644
0
 
LVL 32

Expert Comment

by:Erick37
ID: 34111671
The assumption here is that there will always be 2 decimal places in the numbers.
The following removes all '.' and ',' and then converts to a number, divides by 100 to get the decimal back in the right place and then sums the column.

SELECT
      CAST(SUM(CONVERT(NUMERIC(19,2), REPLACE(REPLACE(YourColumn,',',''),'.','')) / 100) AS NUMERIC(19,2))
FROM yourtable
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 167 total points
ID: 34111851
OK, this will take care of the case when there is a mix of number with 2 decimal places and numbers without decimal places e.g. 123.45 and 123

SELECT
      CAST(
            SUM( CASE PATINDEX('__[,|.]%',REVERSE(YourColumn))
                  WHEN 1 THEN CONVERT(NUMERIC(19,2), REPLACE(REPLACE(YourColumn,',',''),'.','')) / 100
                  ELSE CONVERT(NUMERIC(19,2), REPLACE(REPLACE(YourColumn,',',''),'.',''))
                  END)
      AS NUMERIC(19,2)) AS Total
FROM @YourTable
0
 
LVL 4

Assisted Solution

by:parthmalhan
parthmalhan earned 166 total points
ID: 34144509
Try the following Code:

select sum((convert(money,columnname))) from tablename
0
 

Author Closing Comment

by:rgb192
ID: 34220301
thanks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

9 Experts available now in Live!

Get 1:1 Help Now