Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query critiera 1

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
Is it possible to include in a SQL statement the requirement for position 5, or the last character in a column, to be an alpha character rather than a number?

Thank you,
 
for the last character A-Z a-z

where asc(right(fieldname,1)) between 65 and 122

for the 5th position
where asc(mid(fieldname),5,1) between 65 and 122
 
Thank you. So I actually include this statement in the where clause, along with the other where's?

Never seen this done before.
 
Yes both of those are possibilities to put in the where clause. You said or so I assume you meant either condition must be true so I used OR to combine the statments. If you want BOTH to be true then you could use AND.

Code:
Select fieldname, fieldname2
From [Table Name]
Where asc(right(fieldname,1))  between 65 and 122 OR 
    asc(mid(fieldname),5,1)  between 65 and 122

Although, I would use the like operator...

Code:
Select fieldname, fieldname2
From [Table Name]
Where fieldname Like "????[A-Z]*" OR fieldname Like "*[A-Z]"

In my example the statement can be changed if both are true so you don't have to use AND.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top