Solved

Converting this string to integer necessary??

Posted on 2007-11-16
6
148 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 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
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!

 

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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

733 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