Solved

Converting this string to integer necessary??

Posted on 2007-11-16
6
149 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
[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
6 Comments
 
LVL 66

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 66

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 66

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Industry Leaders: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 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