Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 10th, 2003, 01:50 PM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql access syntax question using "LIKE"

Below is a piece of code that takes form input from the user (projectTradesNeeded) and checks it with the access database column (contractorservices), right now it is set "equals to" Id like to have it be LIKE with a wild card on the users input, but I don't know how to write the syntax for it using mysql and the example below..
would I put the "Request.Form("projectTradesNeeded") in parathesis and put "*" the wild cards around it? or would I put quotes?
any help or direction would be appreciated:)

thankyou

mySQL = "SELECT contractorsname, contractorID, contractorservices, address1, address2, city, state, island, zip, phone FROM contractor WHERE";
mySQL = mySQL + " contractorservices = '" + Request.Form("projectTradesNeeded") + "'";
 
Old October 10th, 2003, 03:31 PM
Ned Ned is offline
Authorized User
 
Join Date: Jun 2003
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can try this

mySQL = mySQL + " contractorservices like '" + Trim(Request.Form("projectTradesNeeded")) + "%'";

-Ned
 
Old October 10th, 2003, 05:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i got this run time error when i tried it:

Microsoft JScript runtime error '800a138f'
Object expected



i'm using access but the mysql syntax seems to work with every thing else.. ex: i'm using "+" instead of "&" to concatanate..
any ideas?
 
Old October 10th, 2003, 05:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The problem of Object Expected is caused by the fact that the Trim method is VB Script ASP. AFAIK, JavaScript / JScript does not support the Trim method natively. This should work:
Code:
mySQL = mySQL + " contractorservices like '" + Request.Form("projectTradesNeeded") + "%'";
If you still need to trim the QueryString, you may need to code some additional logic. Otherwise, just leave it out and it should work.

If you want to perform a true LIKE (where the search string can be anywhere in the column's value), you'll need to add an additional % before the Request.Form:
Code:
mySQL = mySQL + " contractorservices like '%" + Request.Form("projectTradesNeeded") + "%'";
BTW, you say MySQL.... Are you referring to the mySQL statement, or are you referring to the MySQL product??

Cheers,


Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Syntax question ThomasWikman BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 May 7th, 2007 01:25 AM
Access database/SQL Server backend Question vbJupiter Access VBA 1 October 6th, 2006 07:59 PM
SQL query question in Access dlamarche Access 3 April 3rd, 2005 10:42 PM
Access VBA - SQL question. Raelz Access VBA 4 February 10th, 2004 11:28 PM





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