• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

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.
0
rudyflyer
Asked:
rudyflyer
2 Solutions
 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now