Subject Re: SQL Filter
From Mervyn Bick <invalid@invalid.invalid>
Date Wed, 28 Aug 2024 14:21:42 +0200
Newsgroups dbase.getting-started

On 2024/08/27 22:16, Simon Catchpole wrote:
> Please could someone help. I am trying to filter on an entryfield and then display the result
> mchoice = form.container1.choicebox1.value
>                 
> q=new query()
> q.sql:=select * from "statements.dbf" where source = "%mchoice%"
> q.active:=true
> form.statementsdatamodule1.statements1.rowset.first()

Welcome to the newsgroups.  The link on the dBASE website provides
immediate access to the newsgroups via Web-News.  Web-News works but it
is definitely not "user friendly".  Having to check regularly,
especially if you want to look at several newsgroups, for replies
becomes a chore.  Fortunately there is a NNTP feed available from
news.dbase.com which allows messages to be delivered to your computer
just like email.

If the email client you use supports NNTP (some do, some don't) simply
set up a new newsgroup feed and select the newsgroups you want to
follow.  Try adding a new account and see if "Newsgroup" is in the list
of options.  No username or password is required and use your
preferences or default values for the various parameters.

If your email client doesn't support NNTP I suggest using Thunderbird to
access the newsgroups.  If you do, the only "quirk" is that you will
need to use the "Follow up" button (not the "Reply" button which is for
email) to reply to messages in the newsgroups.

Although you'll get all the help you need via these newsgroups, if you
are new to dBASE, and especially if you are new to event driven
programming, it will be time well spend working through the tutorial on
Ken Mayer's website.

http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm

As Akshat has pointed out, the % wildcard only works in conjunction with
the LIKE predicate.  One uses the LIKE predicate in a WHERE clause where
one needs to select records where the named field contains the specified
text.  Depending on what one needs the % wildcard can precede or follow
(or both :-) ) the text.

It will help us help you if, rather than typing code into a message, you
copy and paste problem code.  That way there is no chance of typos
creeping in.  It will also help if you give us any error messages.

The code you posted can't possibly run.  It would give you an "Unallowed
phrase" error as one needs to assign a delimited string containing the
actual SQL statement to a query's sql property.  Something like

q.sql:=[select * from "statements.dbf" where source = "%mchoice%"]

This wouldn't actually return a rowset as the syntax is not correct but
it shouldn't cause an error.  :-)  Akshat has given you code to try that
uses the correct syntax.

Mervyn.