Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2004, 07:42 AM
Authorized User
 
Join Date: Sep 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default postal code search

Hi i would like to know how to do the following:

I have a search scripts that works nicely to search my postal codes in my database but i want to have it so it searches only the first 2 caracters in the postal code, right now it queries any caracters in the postal code and outputs all the postal codes that has the field that the user enters in the search field.

This is the query part of the search can someone modify it to my needs and show me how I can do what i'm trying to do.

Code:
' Build our query based on the input.
    strSQL = "SELECT *" _
        & "FROM uic " _
        & "WHERE unitpostalcode LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
        '& "OR unitpostalcode LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
        '& "ORDER BY unitpostalcode;"


Thank you very much.

 
Old October 19th, 2004, 10:30 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi netcrawler,

What is the user entering as search criteria, 2 chars or anything they like?

Cheers,

Chris

 
Old October 19th, 2004, 11:42 AM
Authorized User
 
Join Date: Sep 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

They will be entering their postal code but I want the search query to do a search only within the first 2 caracters and ignore the rest of the postal code here in Canada we have this standard as postal code: a1a1a1 so what i need to have done is have the query do a search only on the first a1 and disregard the rest of the 4 caracters.

Thanks.
 
Old October 19th, 2004, 11:57 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey netcrawler,

You should be able to do something like...
Code:
' remove any single quotes (unless needed in Canada)
strSearch = Replace(strSearch, "'", "")

' trim to two chars if required
If Len(strSearch) > 2 Then
    strSearch = Left(strSearch, 2)
End If 

' build query using wild card on the right only so the left chars match left chars in the db
' Build our query based on the input.
    strSQL = "SELECT * FROM uic " & _
        "WHERE unitpostalcode LIKE '" & strSearch & "%' " & _
        "ORDER BY unitpostalcode;"
HTH,

Chris

 
Old October 19th, 2004, 12:44 PM
Authorized User
 
Join Date: Sep 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats works nice nice work... Thks, ok lets improve the search little bit, here is the scenario:


if 2nd caracter of the postal code is = to 0 then search all 6 caracters---> example A03 K9R then the query would search all 6 caracters.

and

if 2nd caracter of the postal code is between 1-9 search the 2 first caracters ---> example K4K 1K7 then the query would search only the 2 first caracters.

Thanks.

 
Old October 19th, 2004, 01:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
' trim to two chars if required
If Len(strSearch) > 2 Then
    strSearch = Left(strSearch, 2)
End If
Replace the code given above with the one that follows below.
Code:
If Len(strSearch) > 2 Then
    strSearch1 = Left(strSearch, 2)
End If

If CInt(Right(strSearch1,1))>0 then strSearch = strSearch1
The same strSQL works well for both, so no changes needed in the query suggested by Chris.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me by giving code for this search button csateesh ASP.NET 1.0 and 1.1 Professional 1 August 7th, 2007 07:40 AM
I want search code of beginning c# much C# 1 April 1st, 2006 05:06 AM
code to search a record Rudner VB Databases Basics 1 November 17th, 2004 11:52 PM
Postal code search netcrawler Classic ASP Databases 3 September 30th, 2004 09:37 AM
help with my Search code !! shopgirl Classic ASP Databases 9 February 26th, 2004 06:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.