使用 PIVOT 从 SQL Server 2005 查询创建记录集时遇到问题
这是我的存储过程的输出代码:
SELECT *
FROM
(
select q.ccypair, q.vega, t.label
from #parallel q
LEFT JOIN TPRR_vega_weights t ON q.Tenor = t.Tenor
) a
PIVOT
(
Sum(Vega)
for a.label in ([t1],[t2],[t3],[t4],[t5],[t6],[t7],[t8],[t9],[t10],[t11],[t12],[t13],[t14],[t15],[t16],[t17],[t18])
)p
order by ccypair
在 SQL Server Management Studio 中工作正常,但是当我尝试在 Excel VBA 中打开它时,我得到一个 关闭 ADODB.Recordset (我使用普通版本测试了相同的代码) select * from x query 就可以了)。
有什么想法吗?
Here's the output code from my stored proc:
SELECT *
FROM
(
select q.ccypair, q.vega, t.label
from #parallel q
LEFT JOIN TPRR_vega_weights t ON q.Tenor = t.Tenor
) a
PIVOT
(
Sum(Vega)
for a.label in ([t1],[t2],[t3],[t4],[t5],[t6],[t7],[t8],[t9],[t10],[t11],[t12],[t13],[t14],[t15],[t16],[t17],[t18])
)p
order by ccypair
Works fine in SQL Server Management Studio, but I get a closed ADODB.Recordset when I try to open it in Excel VBA (I tested the same code with a vanilla select * from x query and it was fine).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,这不是导致问题的枢轴,只是未能在存储过程中设置 NOCOUNT ON
in the end, it wasn't the pivot causing the problem, it was just failure to SET NOCOUNT ON in the stored proc
我的想法是ADO 不知道如何正确处理pivot 语句。如果您使用 DAO,我会说使用直通查询,不需要或 ADO 中的选项。
你能把你的sql语句放在存储过程中并调用存储过程吗?这样 ado 只处理返回的数据。
My thought is that ADO doesn't no how to handle the pivot statement correctly. If you where using DAO I would say use a passthrough query, not needed or an option in ADO.
Are you able to put your sql statement in a stored procedure and call the stored procedure? This way ado is only working with the returned data.