ASP and SQL Server Select with LIKE

Posted on 2006-03-20
Last Modified: 2008-03-04
I have a stored procedure that does a:
SELECT company_name from COMPANY where company_name = @company
My ASP is:
dim company

company = Request.Form("company")

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "sp_company_search" & chr(39) & company & chr(39)
objRS.Open strSQL, objConn, , adCmdStoredProc

How can I change this for a like statement so that it will look for a company_name LIKE what was entered.  For example, if the user enters "ABC" into the text field the query will return "ABC Corp" as a result.

Thanks in advance.
Question by:rudyflyer
    LVL 142

    Accepted Solution

    you might pass a %

    strSQL = "sp_company_search" & chr(39) & company & "%" & chr(39)

    the code in the procedure:
    SELECT company_name from COMPANY where company_name LIKE @company
    LVL 10

    Assisted Solution

    Or, if you only want to make a change in one place:

    Change the sotred procedure to:

    SELECT company_name from COMPANY where company_name LIKE @company + '%'

    If you want a search for "BC" to also find "ABC Corp", you chould change the stored procedure to look like:

    SELECT company_name from COMPANY where company_name LIKE '%' + @company + '%'

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    733 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

    21 Experts available now in Live!

    Get 1:1 Help Now