Variable in SQL Statement

Sarah Reichelt sarah.reichelt at gmail.com
Mon Feb 5 21:46:56 EST 2007


On 2/6/07, Jeff Honken <jhonken at webdsp.com> wrote:
> I've been trying to put a wildcard "%" into a SQL statement that
> contains a variable.  I just can't seem to find the right format.
> Here's the SQL statement:
>
> put revQueryDatabase(gConID, "SELECT ClaimNum FROM AccountEntry WHERE
> ClaimNum LIKE '" & QueryDate & "'&% ORDER BY ClaimNum DESC LIMIT 1")
> into q
>
> I've tried the &% and various other combinations with no luck. Can
> someone please point me in the correct direction for this statement.

While others have solved your problem, I would like to share my
technique for dealing with such things. I construct the SQL query or
the AppleScript call or the shell command or the script that I want to
"do" and put it into it's own variable. Then I use the variable in the
main function but when I get a problem, I "put" the variable so that I
can see why it's gone wrong. When constructing strings with quotes,
file paths etc, this makes for much easier debugging.

In your example, I would have done this:
put "SELECT ClaimNum FROM AccountEntry WHERE ClaimNum LIKE '" &
QueryDate & "'&% ORDER BY ClaimNum DESC LIMIT 1" into tQuery
put tQuery  -- for debugging
put revQueryDatabase(gConID, tQuery) into q

Cheers,
Sarah



More information about the use-livecode mailing list