Solved

convert str to int

Posted on 2006-07-20
10
816 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 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

16 Experts available now in Live!

Get 1:1 Help Now