Using variables in SQL statements

lee.bourne

Member
Hi,

I'd like to write something like this but haven't quite got the syntax correct.

sTable = cbxTables:SCREEN-VALUE.
DELETE FROM VALUE(sTable).

The errors that come up are "Unable to understand after -- "DELETE". (247)" and "Line. Invalid SQL Statement. (945)"

The idea being that cbxTables is a combo box full of table name and which ever entry is selected is the one that has all its entries deleted.

Thanks,

Lee
 
R

Ric Lambert

Guest
dont think you can do that

but try this


Def Var hThisQuery As Handle No-undo.
Def Var hThisTable As Handle No-undo.
Def Var lResult As logi No-undo.
Def Var cPrepare As Char No-undo.
Def Var sTable As Char No-undo.

sTable = cbxTables:SCREEN-VALUE.

Create Query hThisQuery.
Create Buffer hThisTable For Table sTable .
lResult = hThisQuery:Set-buffers(hThisTable).
cPrepare = 'For each ':U + sTable + ' exclusive':U.
lResult = hThisQuery:Query-prepare(cPrepare) No-error.
lResult = hThisQuery:Query-open.
DEL-LOOP:
Repeat Transaction:
hThisQuery:Get-next().
If hThisQuery:Query-off-end
Then Do:
Leave DEL-LOOP.
End.
lResult = hThisTable:Buffer-delete().
End.
Delete Object hThisQuery.
Delete Object hThisTable.

Message imported from PEG email list
 
Top