I have wrote a small query from a linked server with a pivot table. What I am tying to do is order the pivot table by the date (LPREDT), the error I keep getting is 'invalid column name LPREDT'. Any help would be great, I have tried to figure this out and I am starting to get frustrated, thanks
select * from OpenQuery
(TNPROD,
'SELECT LPRUSR, LPREDT, LPRACT, LPRTOC
FROM U_FILES.ILCLPR
WHERE LPRACT = ''PICK CTNS''
ORDER BY LPREDT DESC
') AS y
PIVOT (
SUM(LPRTOC)
FOR[LPRACT] IN ([PICK CTNS])
) AS p
ORDER BY LPREDT DESC - this is where I get the error.
Thanks.