ASP and SQL Server Select with LIKE

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.
rudyflyerAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
0
 
thefritterfatboyCommented:
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 + '%'
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.