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
Solved

Converting this string to integer necessary??

Posted on 2007-11-16
6
146 Views
Last Modified: 2010-04-30
I have a data value from my SQL database that lists the Age as Text.  When I do the following string in VB , do I need to convert the Age to Integer in thisstatement?

esql = "select Age From frmRegistrationCSW Where Age >= 12
0
Comment
Question by:al4629740
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20300924
>I have a data value from my SQL database that lists the Age as Text.
Someone did a bad job modeling that one.

>to convert the Age to Integer in thisstatement?
There problem here is that since it's a text field, if there is any non-numeric values, it'll error your expression.

Using this assumes that there are no non-numeric values.
WHERE CInt(Age)> 12
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 20300934
Covering non-numeric values and NULL values, this is probably what you'll need...

select Age From frmRegistrationCSW Where IsNumeric(Age) and Nz(Age, 0) > 12
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20300984
SELECT Age
FROM frmRegistrationCSW
WHERE IsNumeric(Age) And Not IsNull(Age) And Val(Age) > 12

by the way, frmRegistrationCSW is a table?  (a prefix of frm implies form)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:al4629740
ID: 20300986
I get CInt is not a built-in recognized name
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 250 total points
ID: 20301081
The type in the query should match the type in the table:

esql = "select Age From frmRegistrationCSW Where Age >= '12'"

But comparisons will not work as you expect if you try to compare text as if they were numbers,

"20"  is greater then "100" alphabetically.

Make the Age a numeric field and keep your existing sql.
0
 

Author Comment

by:al4629740
ID: 20301082
Yes, it is a table.  Again bad use of terms throughout this program and database.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

829 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