繁体   English   中英

Excel:从 ODBC 文件刷新 SQL

[英]Excel: refresh SQL from ODBC file

我正在使用 Excel 2010 使用 ODBC 数据连接读取一些 SQL 数据。 为此,我有 .odc 连接文件,我可以通过“数据”选项卡和“现有连接”按钮访问这些文件。 Excel 找到 ODC 文件,它可以从中检索数据就好了。 Microsoft Query 也可以编辑查询没问题。

问题,也是我选择 .odc-files 的原因,是我希望能够更改查询的基础数据源以及查询本身。 你看,这个数据是模拟 output,我在 Excel 中进一步处理; 模拟器输出一个 SQLite 数据库。 我定期在模拟器中进行更改以修复错误,然后重新运行以获取新数据。 output 格式(即表结构和格式等)是相同的,只是数据不同。

因此,我们的想法是能够只编辑 .odc 文件以使用具有较新模拟结果的数据库,在 Excel 中刷新,然后完成它(.odc 文件包含连接字符串和 SQL 字符串) . 通过可怕的错误“始终使用此连接”复选框后,我发现 Excel 将接受对连接字符串的任何编辑(即更改数据库文件),但它拒绝接受对连接字符串的任何更改SQL。

当然,对 SQL 查询的编辑不应该经常发生,但它们确实偶尔会发生。 在 SQL 中而不是之后在 Excel 中进行一些计算对我来说并不少见,因为坦率地混合“实时”数据表列(或其他任何名称)和“常规”派生列听起来像是一个受伤的世界。 但是,当我在这些计算中出错时,我想更新它们,这意味着更新 SQL。

所以显然 Excel将从ODC 文件中读取连接字符串,但会很高兴地忽略其中的 SQL 查询,并且(我认为)将其存储在 XLS 文件中。 我只能想象如果您在公司环境中并且有一些分析查询或存储在 ODC 文件中的内容,却发现您可以在公司范围内的每台计算机上手动进行更改,那会是多么可怕。

我做错了什么,还是这是预期的行为? 有没有办法让 Excel 实际使用 ODC 文件中的 SQL 而不是始终使用其本地版本?

一些东西:

Part 1
 - Create a template .ODC file.  
    - Create a connection Data tab, From Other Sources, follow the wizard, connect to the DB and data table.
 - Go to the Data tab, Connections and set the connection properties that you want.
 - Export the connection

Part 2
 - Create the working SQL query for SQLite that produces the desired results
 - Put the entire SQL query on one line (odc files like everything on one line, don't ask)

Part 3
 - Right click on the .odc file, use 'Open with' and open it in notepad or notepad++ (NOT WORD)
 - Look for <odc:CommandText> </odc:CommandText>
 - Remove the text that is there and paste your one line query between the commandtext tags
 - Save the .odc file
 - Double click on the .odc file and see if the data opens/appears in Excel

Don't forget to double check to make sure the data in the <odc:ConnectionString> </odc:ConnectionString> is correct.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM