Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««123

CTE with Linked Server: Mulitpart Identifier could not be bound Expand / Collapse
Author
Message
Posted Monday, July 21, 2014 11:56 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 4:14 PM
Points: 12, Visits: 61
Thanks all, appreciate the feedback.

I did try pulling out the synonyms to simplify the troubleshooting and still ran into the same issue while it was broken. For now, my code is working though and it difficult to troubleshoot.

I am going to add in the TRY CATCH as describe by LutzM (Thanks) and see what parts are breaking when it does fail.
LutM - do you have a recommendation for how to capture the output?

I will also look into the openquery function as suggested by Lynn Pettis (Thanks) and the followup with EXECUTE AT linkedserver from ChrisM@home

Thanks all for helping this newb oh now bumped to Grasshopper status
Post #1594734
Posted Monday, July 21, 2014 12:01 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 20,801, Visits: 32,730
ChrisM@home (7/21/2014)
Lynn Pettis (7/21/2014)
Just a thought, but I was wondering if the following would work:


SELECT WorkOrder, TakTime
INTO
[plc].[TaktTime]
from openquery([SAPETL],'
WITH TaktValues ([Counter], NODE, PLNNR) AS
(
SELECT
MAX(plpo1.ZAEHL) AS [Counter], MAX(plpo1.PLNKN) AS NODE, plpo1.PLNNR
FROM
[ERP].[erp].PLPO plpo1
GROUP BY plpo1.PLNNR
)
SELECT
s022.AUFNR AS WorkOrder,
(CASE
WHEN plpo.SPLIM = 0 THEN 0
ELSE plpo.VGW01/plpo.SPLIM
END) AS TaktTime
FROM
[ERP].[erp].S022 s022
INNER JOIN
[ERP].[erp].AFPO afpo on afpo.AUFNR = s022.AUFNR
INNER JOIN
[ERP].[erp].AFKO afko on afko.AUFNR = s022.AUFNR
INNER JOIN
[ERP].[erp].PLPO on plpo.PLNNR = afko.PLNNR
INNER JOIN
TaktValues ON plpo.PLNNR = TaktValues.PLNNR
AND plpo.ZAEHL = TaktValues.[Counter]
AND plpo.PLNKN = TaktValues.NODE
WHERE
s022.AUFNR IN (SELECT DISTINCT WorkOrder FROM plc.AlarmData)
ORDER BY
s022.AUFNR DESC
');




That's the one. EXECUTE() AT linkedserver is good too.


Haven't used EXECUTE() AT linkedserver, so I can't really say. I have and do use the OPENQUERY method of pulling data from one server to another, just not on a regular basis.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1594739
Posted Monday, July 21, 2014 12:07 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 10:48 AM
Points: 1,037, Visits: 6,956
Hi Lynn, EXECUTE() AT allows you to run a batch of statements, including for instance running results into a temp table for further processing.


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Post #1594741
Posted Monday, July 28, 2014 11:34 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 4:14 PM
Points: 12, Visits: 61
Once again this morning, the job failed and has continued to fail. I tried the below as well as a try catch and both are yielding the same result. I'm am talking with our SAP analyst in regards to those tables as it appears that it the error is coming from that server.

Lynn Pettis (7/21/2014)
Just a thought, but I was wondering if the following would work:


SELECT WorkOrder, TakTime
INTO
[plc].[TaktTime]
from openquery([SAPETL],'
WITH TaktValues ([Counter], NODE, PLNNR) AS
(
SELECT
MAX(plpo1.ZAEHL) AS [Counter], MAX(plpo1.PLNKN) AS NODE, plpo1.PLNNR
FROM
[ERP].[erp].PLPO plpo1
GROUP BY plpo1.PLNNR
)
SELECT
s022.AUFNR AS WorkOrder,
(CASE
WHEN plpo.SPLIM = 0 THEN 0
ELSE plpo.VGW01/plpo.SPLIM
END) AS TaktTime
FROM
[ERP].[erp].S022 s022
INNER JOIN
[ERP].[erp].AFPO afpo on afpo.AUFNR = s022.AUFNR
INNER JOIN
[ERP].[erp].AFKO afko on afko.AUFNR = s022.AUFNR
INNER JOIN
[ERP].[erp].PLPO on plpo.PLNNR = afko.PLNNR
INNER JOIN
TaktValues ON plpo.PLNNR = TaktValues.PLNNR
AND plpo.ZAEHL = TaktValues.[Counter]
AND plpo.PLNKN = TaktValues.NODE
WHERE
s022.AUFNR IN (SELECT DISTINCT WorkOrder FROM plc.AlarmData)
ORDER BY
s022.AUFNR DESC
');


Post #1596989
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse