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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running a command that is in a variable 1

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
In my membership database I have a form from which the user can select 'boilerplate' operations.

one such is SQL ='replace select = .t. For office = 7'

In the past I'm sure I was able to run this type of thing as a macro using &SQL.

Although entering the expression into the command window works I get an error when I run the &SQL.

Can anyone help please?

Thanks

GenDev
 
Hi!
"Replace fieldname WITH .T. for var = value" . [not fieldname=.T.]
Also a fieldname 'select' might cause trouble for select is a command as well.
-Bart
 
Hmmm

I think your expression is what is causing the problem

Code:
SQL = 'Replace Select with .t. for Office =7'
&SQL

But you could probably do better with the Evaluate() function.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
As the others point out, there is no way that will work in the command window because it's a syntax error.

And remember that REPLACE is not an SQL command. When you call it that, you may get confused responses. But I suspect you may already know that and your question was somehow obfuscated.
 
Yes, you got the answers.

The corresponding sql would include the table name and be:

Code:
lnOffice = 7 && or Thisform.txtOffice.Value (just check it's a numeric value)
Update tablename Set Select=.f. Where office=m.lnOffice

Quite similar and easy to translate, isn't it? SQL offers other syntaxes for WHERE conditions, eg field LIKE '%some??thing%' or field Between value 1 and 2, also subselects. Much more capable than replace, but in this case both work about the same way and with equal performance.

No matter if update or replace, why would you first put it into a string and then execute it? Execute it directly. You only need macro substitution, if you want to change something substantially at runtime, not just another office number or so.

Bye, Olaf.
 
Thanks Olaf,

Your SQL was the clue I needed.

My boilerplate SQL statements now work a treat.

Thanks to everyone else who contributed

GenDEv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top