Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert to 0.00

Posted on 2010-11-11
9
Medium Priority
?
297 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
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Accepted Solution

by:
mkobrin earned 668 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

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 668 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 664 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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