Solved

Converting this string to integer necessary??

Posted on 2007-11-16
6
144 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

12 Experts available now in Live!

Get 1:1 Help Now