Solved

convert a varchar to a number in ms sql

Posted on 2007-04-03
3
2,799 Views
Last Modified: 2013-12-24
Hi, what is the sql statement to convert a varchar to a number.  I'm trying to run a query that grabs all prices that are either less than, more than, or equal to a value but need to convert those values first.  Currently, the prices have commas in them such as 100,000 and I need them to return like 100000.  My database is ms sql server 2000.
0
Comment
Question by:COwebmaster
3 Comments
 
LVL 2

Assisted Solution

by:kathik
kathik earned 150 total points
Comment Utility
I would do this:    cast(replace([price],',''') as int)

Remove the commas with replace, then use cast to cast the value to an integer.
0
 
LVL 10

Assisted Solution

by:ksaul
ksaul earned 150 total points
Comment Utility
If the the source column is a varchar with a comma in the text you have to remove the comma before converting it to an int datatype.  

SELECT CAST(REPLACE('100,000',',','') AS int)

You can convert it directly to money datatype:
SELECT CAST('100,000' AS money)

Or to money and then to int
SELECT CAST(CAST('100,000' AS money) AS int)
0
 
LVL 24

Accepted Solution

by:
dgrafx earned 200 total points
Comment Utility
where column > convert(money,#b#)
in this example - #b# is your value such as 100,000
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

763 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

7 Experts available now in Live!

Get 1:1 Help Now