Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CTE with Linked Server: Mulitpart Identifier could not be bound


CTE with Linked Server: Mulitpart Identifier could not be bound

Author
Message
DevNate
DevNate
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
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
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24206 Visits: 37967
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.

Cool
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)
ChrisM@home
ChrisM@home
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1161 Visits: 9736
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
DevNate
DevNate
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
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
');




Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search