Pivot Table query from SQL tables gives error - sometimes
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 WorkOrderN开发者_Python百科o from @WCsWithDups group by WorkOrderNo having count(WorkOrderNo) = 1);
select distinct WOStatus, WOCreated, WorkOrderNo, 'Shed+OP' as WorkCenterID, ItemClassID, StockItem, FirstChar, MaxWODays
from @WCsWithDups
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
PowerPivot supports only one recordset in your case by executing insert and delete you will get multiple result sets which could be the problem.
精彩评论