?
Solved

convert str to int

Posted on 2006-07-20
10
Medium Priority
?
829 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
[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
10 Comments
 
LVL 66

Expert Comment

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

Assisted Solution

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

Accepted Solution

by:
Jim Horn earned 1000 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 66

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

770 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