×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Using one user entered field to perform multiple searches

Using one user entered field to perform multiple searches

Using one user entered field to perform multiple searches

(OP)
I have a field called "zip". The user enters a full 5 digit zip code in the field. My script & SQL statement then accesses the database and shows all the matches for that full zip code. What I want to happen next is perform a search on just the first 3 digits of the zip code to give a regional results list. How do I manipulate my "zip" field to only contain the first 3 digits. I am an RPGIV AS/400 programmer who is new to vbscripting. I do not know of an opcode to let me do this. Thanks for your help!

RE: Using one user entered field to perform multiple searches

Okay, so I am assuming you are accessing your DB thru ASP so here goes some ASP pseudo code that will do what you ask. The gist of it... use a combination of the "LIKE" SQL keyword and "LEFT" VBScript function...

Note: You didn't specify whether the zip field is numeric or string. I assume it is string for two reasons: 1. There is no reason for it to be numeric as you probably won't be performing mathematical operations on a zip field. And 2. Zip+5 uses a hyphen which requires it to be string.


'declare your ADO objects

SQL = "select * from table where zip = '" & Request("zip") & "'"

'open the recordset, loop thru the RS and display the results of this first query.

SQL = "select * from table where zip LIKE '" & Left(Request("zip"),3)% & "'"

'open the second recordset and do what you like

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close