Solved

convert string to integer

Posted on 2013-05-23
3
329 Views
Last Modified: 2013-05-23
I have a column that is nvarchar(50) called Number1.  How do I convert the string to a number?

select * from table where Number1 > 0
0
Comment
Question by:al4629740
[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
  • 2
3 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 150 total points
ID: 39191479
Your query should work as 0 is an integer, the data from 'Number1' will be converted to integer

or else if you want explicit conversion

select * from table where cast(Number1 as bigint )  > 0
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 150 total points
ID: 39191492
-- Here's how you select it as an integer..
select CAST(Number1 as int)  
from table

Depending on your situation you'll want to validate whether Number1 really is an integer, either because it has decimal values (12.3) or it's a string ('banana')

-- This will weed out all of the non-numeric values.
select CAST(Number1 as int)  
from table
where ISNUMERIC(Number1) = 1


-- Then you'll have to decide if you want to weed out the decimal values, or round them.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39191542
Thanks for the split.  Good luck with your project.  -Jim
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

728 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