jackii:我想要实现的SQL查询比举的例子更为复杂:
如
if a>1
update table
else
insert into table
etc
或
select t=je from tablea
select t1=je from talbeb
select t as a, t1 as b
其中的A和B为QUERY的个字段
如何能实现呢?
请教yijun2000:
能否说得具体点是用DELPHI中的语句来实现吗?
如果我的程序中的QUERY是:
if @a>1
begin
select * from TableA
end
els
begin
select * from tableB
end
这样若不用SUNNYWINTER的动态修改SQL的办法,如何实现?
在delphi 的Qurey控件中,只能使用Sql语句,不能使用结构语句,你需要对*.dbf进行操作,可在程序中使用IF,而不是在Qurey中具体使用看程序而定。以下给你一个例子:
...
query1.close;
query1.sql.clear;
query1.sql.add('select * from ''a.dbf'' where');
if edit1.text<>'' then
query1.sql.add('name='''+edit1.text+'''') {如果edit1不为空,则name字段等于其内容}
else if edit2.text<>'' then
query1.sql.add('no='''+edit2.text+'''');{如果edit1为空,而edit2不为空,则no字段等于edit2的内容}
query1.open;
...