通过代码修改查询的sql [英] Revise query's sql via code

查看:52
本文介绍了通过代码修改查询的sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式编辑查询?大多数表名都已更改(我们无法控制)。所以现在我们必须编辑每个查询,以便它使用新表的名称。而不是进入每个查询&手动进行更改,是否可以通过代码完成,因为有很多查询?我们需要改变的是,如果表名不是以tbl开头,那么它需要dbo。放在名字前面。我在使用ADOX.Catalog&之前修改了查询。 ADODB.Command但实际上是在代码中编写sql。我需要做的是循环遍历数据库中的每个查询(我在列表框中列出)&为每一个获取sql,对表名进行更改&然后保存它。我们有Access 2000.我们确实打开了自动更正,但是没有对Criteria部分中的任何内容进行更改。


TIA任何建议。

Is there a way to edit queries programmatically? Most all of the table names have changed (something we had no control over). So now we have to edit each query so it''s using the new tables'' name. Instead of going into each query & make the changes manually, can it be done via code, as there are a lot of queries? What we need to change is if the table name doesn''t start with "tbl", then it needs "dbo" placed in front of the name. I''ve modified queries before using the ADOX.Catalog & ADODB.Command but that''s actually writing the sql in code. What I need to do is loop thru each query in the db (which I have listed in a listbox) & for each one get the sql, make the changes to the table names & then save it. We have Access 2000. We did turn the AutoCorrect on, but that didn''t make changes to anything in the Criteria section.

TIA for any suggestions.

推荐答案


有没有办法以编程方式编辑查询?
Is there a way to edit queries programmatically?



是的


cpStar,你将不得不和我待在一起!

Yes

cpStar, you''re gonna have to stay with me on this one!

  1. 你需要创建2 For ... Next Nested Loops。
  2. 外环将生成所有未以''tbl'开头的表名',并且不是系统表,即NOT?Sys。
  3. 内循环将检索所有不是临时对象的查询,即NOT~sq *。
  4. 每个符合条件的表都是现在,对每个符合条件的查询进行交叉引用。
  5. 代码现在检查表名是否通过其SQL属性和Instr()函数出现在查询中。
  6. 如果表名称确实/确实出现,其名称现在将通过Replace()函数以dbo开头。这样做有效的是通过SQL属性动态修改查询/查询的基础SQL语句。
  7. 算法发布如下。它接近我的睡觉时间,并没有经过彻底的测试。不要在你的现场数据库上测试这个算法!对于可能发生的任何重大结果,我不承担任何责任!所有这一切,这里是代码,任何问题,随时问。
  8. 祝你好运!

展开 | 选择 | Wrap | 行号


您好ADezii,


这完全有道理!我和ADO一起工作很多,我忘了DAO有时会更有帮助...&更容易使用。非常感谢您的快速回复。我今天会试试这个&会告诉你这件事的进展的。如果你问我们是否希望这些表格也重命名,答案是否定的,因为我们会重新安排它们。


再次感谢您的帮助!
Hi ADezii,

That makes total sense! I work a lot with ADO, that I forget that DAO can sometimes be more helpful ... & easier to use. Thank you so much for your quick response. I''ll try that today & will let you know how it goes. If you were asking if we want the tables also renamed, the answer is no as we''ll be relinking them.

Thanks again for your help!

很高兴为您提供帮助,请告诉我们您的具体情况。
Glad to help, let us know how you make out.


这篇关于通过代码修改查询的sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆