[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

convert string to integer

Posted on 2013-05-23
3
Medium Priority
?
341 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
  • 2
3 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 600 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 600 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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
Suggested Courses

873 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