我正在尝试在MS Excel VBA中对odbc运行查询,该查询从MySQL数据库中选择一些数据。 查询保持不变,但有一个输入参数会发生变化。
SELECT ips_model_ips_assets.ips_asset_id,
ips_assets.name,
ips_model_ips_assets.allocation,
ips_assets.ips_beta,
report_categories.name,
ips_assets.eu,
ips_assets.uk,
ips_assets.us,
ips_assets.jp,
ips_assets.asia,
ips_assets.em,
ips_assets.global,
ips_assets.other
FROM ips_model_ips_assets
LEFT JOIN ips_assets
ON ips_model_ips_assets.ips_asset_id = ips_assets.id
LEFT JOIN report_categories
ON ips_assets.report_category_id = report_categories.id
WHERE ips_model_ips_assets.ips_model_id = (SELECT ips_model_id
FROM clients
WHERE id = :id)
AND ips_model_ips_assets.rebalance_date = (SELECT Max(rebalance_date)
FROM ips_model_ips_assets
WHERE
ips_model_id = (SELECT ips_model_id
FROM clients
WHERE id = :id))
出现了一个非常奇怪的问题::id
某个值我得到以下错误:
[MySQL] [ODBC 5.2(a)驱动程序] [mysqld-5.5.32]数值超出范围
该查询可以完美地用于其他:id
。另外,当我在mysql中直接运行有问题的查询时,它运行正常 - 只有在vba中才会发生错误。我检查了我的数据库表,所有数据类型都是正确的,似乎没有任何会导致数据类型问题。这是一个示例输出:
| 1 | Cash GBP | 0.125 | 0 | Cash | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 64 | Winton Ucits | 0.0726 | 0.59 | CTA | 0.285 | 0.095 | 0.421 | 0.032 | 0.075 | 0.092 | 0 | 0 |
| 91 | Bluetrend listed | 0.0176 | 0 | CTA | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 89 | Schroder UK Dynamic Fund | 0.0858 | 0.2 | Equity LS | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 8890 | RWC Europe Absolute Alpha Fund | 0.0338 | 0.4 | Equity LS | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 90 | JPMorgan EDLS | 0.0555 | 0.4 | Equity LS | 0.657 | 0.343 | 0 | 0 | 0 | 0 | 0 | 0 |
| 88 | GLG Japan Core Alpha | 0.0387 | 0.941 | Equity LO | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 66 | iShares MSCI World ETF | 0.113 | 1 | Equity LO | 0.1575 | 0.095 | 0.534 | 0.09 | 0.05 | 0.0235 | 0 | 0.05 |
| 72 | Blackrock European Long Only | 0.0283 | 1.008 | Equity LO | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 55 | iShares DJ Euro STOXX 50 | 0.0272 | 1.063 | Equity LO | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 37 | Odey Developed Markets | 0.0635 | 1.2 | Equity LO | 0.186 | 0.324 | 0.314 | 0.049 | 0.035 | 0 | 0 | 0.092 |
| 134 | iShares S&P 500 | 0.026 | 0.942 | Equity LO | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 8894 | Neptune European Opportunities | 0.0321 | 1.064 | Equity LO | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
编辑:
我的VBA代码的这一行出现问题:
If Rs.RecordCount <> 0 Then //Rs is the recordset
由于某种原因,司机似乎无法获得记录。运行Rs.GetRows
也会失败并出现相同的错误。如果我检查监视窗口中的Rs
,我可以看到它包含查询结果,但没有任何内容可以指示导致此错误的任何内容。最奇怪的是它在某些时候才会失败。