September 17, 2013 at 2:02 pm
Hello guys, i need so much your help!
I was doing an insert statement with union all using a linked server.
I have two dabases in two different servers. These databases are connected through a linked server.
When i try to do an insert statement with union all from a database to another, using linked server, i receive the following message:
"Msg 8624, Level 16, State 17, Line 1
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services."
Someone could help me?!?!
I'm sorry for the language, I'm brazilian!!
September 17, 2013 at 2:54 pm
check out the workaround in this connect item. http://connect.microsoft.com/SQLServer/feedback/details/228950 It's pretty old so I don't know if it is applicable anymore.
you might also want to look at the permission of the linked server user. If it is not sysadmin, db_owner, or db_ddladmin then you might be having an issue using statistics or if you do have these permission the statistics may be out of date. http://blogs.technet.com/b/mdegre/archive/2012/12/11/8624-internal-query-processor-error-the-query-processor-could-not-produce-a-query-plan.aspx
September 17, 2013 at 11:59 pm
Can you please post your code that you have written?
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
September 18, 2013 at 6:07 am
INSERT INTO [LINK_OVERFLY_NFE].NFE_4.dbo.NumeroSerie_Item (ListaEmbalagem_ItemID, NumeroSerie, NotaFiscal, dtNotaFiscal, Fornecedor, Documento, Quantidade)
SELECT NFItens.NFItemID, NumerosSerie.NumeroSerie AS NumeroSerie,
dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, NumerosSerie.NumeroSerie, 1) AS NotaFiscal,
dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, NumerosSerie.NumeroSerie, 2) AS Data,
dbo.fn_Consultema_TrataCaracterEspecial(dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, NumerosSerie.NumeroSerie, 3),1) AS Fornecedor,
dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, NumerosSerie.NumeroSerie, 4) AS Documento, 1 AS Quantidade
FROM Pedidos WITH(NOLOCK)
INNER JOIN Pedidos_Itens Itens WITH(NOLOCK) ON (Pedidos.PedidoID = Itens.PedidoID)
INNER JOIN NotasFiscais_Itens NFItens WITH(NOLOCK) ON (Pedidos.NotaFiscalID = NFItens.NotaFiscalID AND Itens.PedItemID = NFItens.PedItemID)
INNER JOIN NumerosSerie_Movimento Movimentos WITH(NOLOCK) ON (Itens.PedidoID = Movimentos.PedidoID)
INNER JOIN NumerosSerie WITH(NOLOCK) ON (Movimentos.NumeroSerieID = NumerosSerie.NumeroSerieID AND Itens.ProdutoID = NumerosSerie.ProdutoID)
WHERE (Pedidos.NotaFiscalID = 1802725)
GROUP BY NFItens.NFItemID, Pedidos.EmpresaID, Pedidos.PedidoID, Itens.ProdutoID, NumeroSerie
UNION ALL /*this is responsible for the error - If i don't use UNION ALL, it works*/
SELECT NFItens.NFItemID, Movimentos.Lote AS NumeroSerie, dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, Movimentos.Lote, 1) AS NotaFiscal,
dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, Movimentos.Lote, 2) AS Data,
dbo.fn_Consultema_TrataCaracterEspecial(dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, Movimentos.Lote, 3),1) AS Fornecedor,
dbo.fn_Produto_Fornecedor(Pedidos.EmpresaID, Itens.ProdutoID, Movimentos.Lote, 4) AS Documento, 1 AS Quantidade
FROM Pedidos WITH(NOLOCK)
INNER JOIN Pedidos_Itens Itens WITH(NOLOCK) ON Pedidos.PedidoID = Itens.PedidoID
INNER JOIN NotasFiscais_Itens NFItens WITH(NOLOCK) ON (Pedidos.NotaFiscalID = NFItens.NotaFiscalID AND Itens.PedItemID = NFItens.PedItemID)
INNER JOIN Pedidos_ProdutosLote Movimentos WITH(NOLOCK) ON (Pedidos.PedidoID = Movimentos.PedidoID AND Itens.ProdutoID = Movimentos.ProdutoID)
WHERE (Pedidos.NotaFiscalID = 1802725)
GROUP BY NFItens.NFItemID, Pedidos.EmpresaID, Pedidos.PedidoID, Itens.ProdutoID, Movimentos.Lote ORDER BY NumeroSerie
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply