Solved

convert str to int

Posted on 2006-07-20
10
821 Views
Last Modified: 2008-02-26
hi,

Please assist how can we convert str to integer?

Select cast(Column1 as Int) From MyTable

Thanks.
0
Comment
Question by:RyanBank
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17147805
SELECT CInt(Column1) FROM MyTable
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 250 total points
ID: 17147807
SELECT VAL(Column1) FROM MyTable
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 17147811
CLng() converts to Long Integer
CStr() converts to String
CDate() converts to Date
CBool() converts to Boolean
CCur() converts to Currency
CDbl() converts to Double

...
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 33

Expert Comment

by:hongjun
ID: 17147829
this will do

Select CInt(Column1) From MyTable
0
 
LVL 33

Expert Comment

by:hongjun
ID: 17147832
so fast!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17147847
(Off Topic)  <Frazier Crane> When you know the answer, it's hard not to hit the buzzer...
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17148144
Ryan, is your data likely to contain nulls or letters?

I say this because VAL converts

Null becomes #Error
123ABC becomes 123
ABC123 becomes 0


Not sure what the conversion functions (as Jim as explained) might return. It may be a data type mismatch (no offence Jim)

So you need to cater for this scenario, thats if u are likely to have them

to stop nulls from falling over, u can wrap field with NZ

VAL(NZ(field,0))

gives a null value to 0, but u can specify what u want


0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 17148978
Ryan,

Just for your information, the C in CInt, CStr, CDate, etc. stands for Cast. I noticed you are familiar with cast.

Chuck
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17149503
Chuck:  VB Editor, Help, Answer Wizard, type - Conversion Functions - and you get all the conversion functions where specifically it talks about "coercing" one datatype to another.  Type in - Cast - and you get an entirely different set of returns, none of which are 'Conversion Functions'  - for what it's worth.
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 17149537
GRayL: I was reading a discussion of these functions in VB.Net and it said that the C was used to "cast" the variable into a different type. Sorry I don't remember where I saw that. In any case, it doesn't matter as cast and convert are fairly synonymous. For those used to cast in  other languages, perhaps it is helpful for them to think in terms of cast instead of convert. Thanks for your input.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

809 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