Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL equivalent to what I know in Foxpro

Status
Not open for further replies.

wtotten

IS-IT--Management
Apr 10, 2002
181
US
I need to find all the records in a table where CUSTNO $ ( a parameter).

In Foxpro I would do this:
cCustList = prompt user to enter in a string
SELECT * FROM customers WHERE custno $ cCustList

I need the same functionality for SQL Server. Somehow I'll need to use a parameter and the equivalent of the Foxpro $ operator.

I need help on what the syntax would be.

Thanks,
Bill
 
Bill,

The usual way of translating the VFP $ operator is to use SQL's LIKE clause.

Brian showed you how to do that. However, I would add another percent sign, like so:

Code:
WHERE custno LIKE '[b]%[/b]Customer%'

You might find it useful to glance at the article at which compares the syntax of SELECT in VFP and SQL Server.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks for your help guys. However, one issue still; the parameter. The string value I am looking for in a field is a parameter in the query, not a literal value. How do I use a parameter in a LIKE clause?

Thanks,
Bill
 
Not quite sure what your environment is, but if you are using SQL passthru from VFP to accomplish this, the format would be something like:
Code:
sqlexec(nHandle,"SELECT * FROM customers WHERE custno LIKE '%"+cCustList+"%'","c_customers")

Normally, in SPT you'd pass a parameter by using the VFP variable name preceded by a percent sign, but since that's the SQL LIKE wildcard, that won't work, so you construct the SQL string the hard way.

If user enters '54321', you want SQL to see the following:

Code:
SELECT * FROM customers WHERE custno LIKE '%54321%'

Mike Krausnick
Dublin, California
 
(slaps forhead) Of course, Mike's right. My bad.

Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top