来自 SQL 表的数据透视表查询有时会出错
使用 PowerPivot 10.50.1747.0 运行 Excel 2010,访问 SQL Server 2005 SP2。
我正在修改 Excel 数据透视表。它通过查询从 SQL 表获取数据。我正在对“表属性”下的查询进行更改。当我输入新查询并单击“验证”按钮时,我得到“SQL 语句有效”。如果我单击“设计”按钮,然后在出现的窗口中单击“运行”(“!”)按钮,我将获得正确的数据。但是,当我退出“设计”窗口并单击“保存”按钮时,我收到错误:
==============
The refresh operation failed because the source data base or the table does
not exist, or because you do not have access to the source
More Details:
OLE DB or ODBC error.
An error occurred while processing the 'Query' table.
The operation has been cancelled.
==============
这里发生了什么? (我正在使用表变量 - 这会导致问题吗?)感谢您的帮助。
这是代码:
declare @WCsWithDups TABLE(
WOStatus Char(1) not null,
WOCreated DateTime not null,
WorkOrderNo VarChar(15) not null,
WorkCenterID VarChar(6) not null,
ItemClassID VarChar(12) not null,
StockItem Char(1) not null,
FirstChar Char(1) not null,
MaxWODays SmallInt not null
)
insert into @WCsWithDups(WOStatus, WOCreated, WorkOrderNo, WorkCenterID, ItemClassID, StockItem, FirstChar, MaxWODays)
select DISTINCT
case
when wocompleted is null then 'O'
else 'C' end as WOstatus,
wocreated,
WorkOrderNo,
workcenterid,
itemclassid,
case when timinventory.minstockqty>0 then 'Y'
when timinventory.maxstockqty>0 then 'Y'
when timinventory.safetystockqty>0 then 'Y'
when timinventory.stdordqty>0 then 'Y'
else 'N' end as stockitem,
left(itemproduced,1) as FirstChar,
(select max(datediff(day,wocreated,transdate)+1) from vdvMT b where TR1.workorderno=b.workorderno) as maxwodays
from vdvMT as TR1
left join tInv on TR1.itemkeyproduced=tInv.itemkey and TR1.whsekey=tInv.whsekey
where type='L' and wocreated>=(getdate()-365) and (workcenterid = 'Shed' or workcenterid = 'OP')
delete from @WCsWithDups
where WorkOrderNo in (
select WorkOrderNo from @WCsWithDups group by WorkOrderNo having count(WorkOrderNo) = 1);
select distinct WOStatus, WOCreated, WorkOrderNo, 'Shed+OP' as WorkCenterID, ItemClassID, StockItem, FirstChar, MaxWODays
from @WCsWithDups
Running Excel 2010 with PowerPivot 10.50.1747.0, accessing SQL Server 2005 SP2.
I am modifying an Excel pivot table. It gets its data from a SQL table, via a query. I am making changes to the query under "Table Properties." When I enter my new query, and click the "Validate" button, I get "The SQL statement is valid." If I click the "Design" button and in the resulting window click the Run ("!") button, I get the proper data. BUT, when I get out of the Design window and click the Save button, I get the error:
==============
The refresh operation failed because the source data base or the table does
not exist, or because you do not have access to the source
More Details:
OLE DB or ODBC error.
An error occurred while processing the 'Query' table.
The operation has been cancelled.
==============
What is going on here? (I am using a table variable - would that be causing the problem?) Thanks for any assistance.
Here is the code:
declare @WCsWithDups TABLE(
WOStatus Char(1) not null,
WOCreated DateTime not null,
WorkOrderNo VarChar(15) not null,
WorkCenterID VarChar(6) not null,
ItemClassID VarChar(12) not null,
StockItem Char(1) not null,
FirstChar Char(1) not null,
MaxWODays SmallInt not null
)
insert into @WCsWithDups(WOStatus, WOCreated, WorkOrderNo, WorkCenterID, ItemClassID, StockItem, FirstChar, MaxWODays)
select DISTINCT
case
when wocompleted is null then 'O'
else 'C' end as WOstatus,
wocreated,
WorkOrderNo,
workcenterid,
itemclassid,
case when timinventory.minstockqty>0 then 'Y'
when timinventory.maxstockqty>0 then 'Y'
when timinventory.safetystockqty>0 then 'Y'
when timinventory.stdordqty>0 then 'Y'
else 'N' end as stockitem,
left(itemproduced,1) as FirstChar,
(select max(datediff(day,wocreated,transdate)+1) from vdvMT b where TR1.workorderno=b.workorderno) as maxwodays
from vdvMT as TR1
left join tInv on TR1.itemkeyproduced=tInv.itemkey and TR1.whsekey=tInv.whsekey
where type='L' and wocreated>=(getdate()-365) and (workcenterid = 'Shed' or workcenterid = 'OP')
delete from @WCsWithDups
where WorkOrderNo in (
select WorkOrderNo from @WCsWithDups group by WorkOrderNo having count(WorkOrderNo) = 1);
select distinct WOStatus, WOCreated, WorkOrderNo, 'Shed+OP' as WorkCenterID, ItemClassID, StockItem, FirstChar, MaxWODays
from @WCsWithDups
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正在扫描未回答的问题 - 看起来OP在其他地方得到了回答:
http://social.msdn.microsoft.com/Forums/en-US/sqlkjpowerpivotforexcel/thread/d7c7bc25-d140-4957-9b66-9963d1c655b1
在插入之前设置不计数并在插入后将无计数设置为关闭
Was scanning unanswered questions - looks like the OP got this one was answered elsewhere:
http://social.msdn.microsoft.com/Forums/en-US/sqlkjpowerpivotforexcel/thread/d7c7bc25-d140-4957-9b66-9963d1c655b1
Set No Count ON before Insert and Set No Count OFF after insert