请大虾帮忙!该如何编写(100分)

  • 主题发起人 主题发起人 d99
  • 开始时间 开始时间
D

d99

Unregistered / Unconfirmed
GUEST, unregistred user!
view1:<br> &nbsp; select a.id,b.name,a.qty, a.price, a.sum from bill a,good b where a.id &gt; 100;<br>view2:<br> &nbsp; select id AS 编码, name AS 名称, sum AS 金额 from view1 where id &lt; 200;<br><br>编程的时候,需要生成第一个动态表view1;然后根据第一个动态表生成第二个动态表view2, 它们的查询条件会动态改变。请问该如何编写代码?(ADO)谢谢!
 
with Adoquery1 do<br>begin<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('create view1 as &nbsp;select a.id,b.name,a.qty, a.price, a.sum from bill a,good b where'+contionstr1 ); &nbsp;//contionstr1 为条件变量例如 ID&gt;100<br> &nbsp; ExecSql;<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('select id AS 编码, name AS 名称, sum AS 金额 from view1 where '+contionstr2); //contionstr2 为条件变量例如 ID&lt;200<br> &nbsp;Open;<br>end;
 
在楼上基础上,每次查询前先判断库里是否有此表,有就删除,再重新创建表并插入根据条件查询出来的数据集,返回给显示控件就可以老
 
感谢李翔鹏、空心!我是菜鸟,请空心给出代码,谢谢!
 
TQuery(完成select a.id,b.name,a.qty, a.price, a.sum from bill a,good b where a.id &gt; 100;<br>)<br> + TProvider(完成TQuery连接TClientDataSet)<br> + TClientDataSet(完成Filter id &lt; 200)
 
with Adoquery1 do<br>begin<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('drop view view1');<br> &nbsp;try<br> &nbsp; &nbsp;ExecSql;<br> &nbsp;except<br> &nbsp;end;<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('create view1 as &nbsp;select a.id,b.name,a.qty, a.price, a.sum from bill a,good b where'+contionstr1 ); &nbsp;//contionstr1 为条件变量例如 ID&gt;100<br> &nbsp;ExecSql;<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('drop view view2');<br> &nbsp;try<br> &nbsp; &nbsp;ExecSql;<br> &nbsp;except<br> &nbsp;end;<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('Create view2 as select id AS 编码, name AS 名称, sum AS 金额 from view1 where '+contionstr2); //contionstr2 为条件变量例如 ID&lt;200<br> &nbsp;ExecSql;<br> &nbsp;Close;<br> &nbsp;Sql.Clear;<br> &nbsp;Sql.Add('select * from view2');<br> &nbsp;Open;<br>end;
 
楼上的语句写得不错呀。学习
 
感谢李翔鹏!问题已解决!
 
多人接受答案了。
 
后退
顶部