Converting this string to integer necessary??

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
al4629740Asked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>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
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
al4629740Author Commented:
I get CInt is not a built-in recognized name
0
 
GrahamSkanConnect With a Mentor RetiredCommented:
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
 
al4629740Author Commented:
Yes, it is a table.  Again bad use of terms throughout this program and database.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.