We help IT Professionals succeed at work.

ASP and SQL Server Select with LIKE

rudyflyer
rudyflyer asked
on
Medium Priority
288 Views
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.
Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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 + '%'
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.