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

How can one select different Folders in a SQL Editor during Runtime? 1

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA

I have the following which works fine.

with qryMyQuery do
begin
SQL.Clear;
SQL.Add('SELECT *');
SQL.Add ('FROM ''C:\h\MyQuery'''); (Where MyQuery is a permanent Folder.)
Active := True;
end;

I need to be able to vary 'MyQuery'during Runtime and am trying to
acheive something like the following.


var
TheQuery : Word; (Or something)

begin

TheQuery := AValue; (Which I will provide and which will vary.)

with qryMyQuery do
begin
SQL.Clear;
SQL.Add('SELECT *');
SQL.Add ('FROM ''C:\h\TheQuery'''); Which isn't going to happen. :)
Active := True;
end;

Anyone have any ideas on this please?

Thanks in advance.

TERRY
 
very easy :

Code:
var s : string;
    qryname : string;

with qryMyQuery do
  begin
    SQL.Clear;
    SQL.Add('SELECT *');
    qryname:='C:\h\MyQuery'; //change this at will at runtime
    s:=format('FROM ''%s''',[qryname]);
    SQL.Add (s);  
    Active := True;
  end;

--------------------------------------
What You See Is What You Get
 
Huston I have a problem!

Thanks to whoserdaddy (above) the following code works.

var
qryname , qryname1, qryname2, qryname3: string;
s,s1,s2,s3: string;

with dmStdAcc.qryGL do
begin
SQL.Clear;
SQL.Add('SELECT *');
qryname := 'C:\h\StdAcc\6\GL';
s:=format('FROM ''%s''',[qryname]);
SQL.Add (s);
Active := True;
end;

However I need to expand on that to something like ...

begin
qryname1 := '''C:\h\StdAcc\6\GL'' t1, ''C:\h\StdAcc\UsrTfr'' t2';
qryname2 := 't1.PNo = t2.PNo';
qryname3 := 't1.GLNo';
with dmStdAcc.qryGL do
begin
SQL.Clear;
SQL.Add('SELECT *');
s1:=format('FROM''%s1''',[qryname1]);
s2:=format('WHERE''%s2''',[qryname2]);
s3:=format('ORDER BY''%s3''',[qryname3]);
SQL.Add (s1);
SQL.Add (s2);
SQL.Add (s3);
Active := True;
end;

Which doesn't work for too many reasons to go into here.

What am I missing? Anyone.

Thanks in advance.


 
hi,

the '%s' in your formatted string represents the token that must be replaced by the format function (for more info about this function, see delphi help about this). so if you write Format('%s1',['test']); , the result will be 'test1' .

why not do this :

Code:
begin
  qryname1 := '''C:\h\StdAcc\6\GL'' t1, ''C:\h\StdAcc\UsrTfr'' t2';
  qryname2 := 't1.PNo = t2.PNo';
  qryname3 := 't1.GLNo';    
  with dmStdAcc.qryGL do
  begin
    SQL.Clear;
    SQL.Add('SELECT *');
    s:=format('FROM''%s''',[qryname1]);
    SQL.Add (s);
    s:=format('WHERE''%s''',[qryname2]);
    SQL.Add (s);
    s:=format('ORDER BY''%s''',[qryname3]);
    SQL.Add (s);
    Active := True;
end;


--------------------------------------
What You See Is What You Get
 
Thanks! As it happens I haved already tried that and get exception
"Invalid use of keyword.
Token:?
WHERE 't.PNo
Line Number:2.'
 
>if you write Format('%s1',['test']); , the result will be 'test1' .

So I discovered. :)
 
I see were your problems lies,
ditch the quotes around %s.
your could should be like this:

Code:
begin
  qryname1 := '''C:\h\StdAcc\6\GL'' t1, ''C:\h\StdAcc\UsrTfr'' t2';
  qryname2 := 't1.PNo = t2.PNo';
  qryname3 := 't1.GLNo';    
  with dmStdAcc.qryGL do
  begin
    SQL.Clear;
    SQL.Add('SELECT *');
    s:=format('FROM %s',[qryname1]);
    SQL.Add (s);
    s:=format('WHERE %s',[qryname2]);
    SQL.Add (s);
    s:=format('ORDER BY %s',[qryname3]);
    SQL.Add (s);
    Active := True;
end;

--------------------------------------
What You See Is What You Get
 
Thanks whosrdaddy! That works perfectly.

But now I apologize if this appears to be a new thread - which belongs somewhere else - because in fact it is not. It relates to the above. Because having successfully
done the above I now find my UpDate procedures won't work. Probably because the Object Code for the TUpdateSQL still look as follows - which is in conflict with what I have done above.

How can I overcome this? Anyone??

object updGL: TUpdateSQL
ModifySQL.Strings = (
'update "c:\h\StdAcc\GL"' // Which is NOT where it is.
'set'
' GLNo2 = :GLNo2,'
' etc = :etc,'
' etc = :etc,'
'where'
' GLNo2 = :OLD_GLNo2')
InsertSQL.Strings = (
'insert into "c:\h\StdAcc\GL"'
' (GLNo2, etc. etc.'0, '
DeleteSQL.Strings = (
'delete from "c:\h\StdAcc\GL"'
'where'
' GLNo2 = :OLD_GLNo2')
Left = 285
Top = 139
end
 
For anyone following this thread NOTE that (obviously) one needs to UpDate this. For a solution visit my thread102-902528
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top