Solved

convert str to int

Posted on 2006-07-20
10
825 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

756 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