Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - OPENQUERY

I am using an Openquey which has been working fine on SQL Server 2005, I have 1 server that is SQL Server 2008 which this does not work on.

If I run the following:

SELECT * 
FROM OPENQUERY([Manchester], 
      '[Manchester].[PilotWebApp].[DBO].rsp_HandheldPerformance ''10/01/2009'', 
      ''10/10/2009''')

I get this error:

Cannot process the object "[Manchester].[PilotWebApp].[DBO].rsp_HandheldPerformance '10/01/2009', '10/10/2009'". 
The OLE DB provider "SQLNCLI" for linked server "Manchester" indicates that either the object has no columns or the current user does not have permissions on that object.

If I just run:

[Manchester].[PilotWebApp].[DBO].rsp_HandheldPerformance '10/01/2009', '10/10/2009'

it works fine. Has something been changed in 2008?

What it does is gets the data from the openquery and inserts into my temp table:

INSERT #TempHandheldPerformance SELECT * FROM OPENQUERY([Manchester], '[Manchester].PilotWebApp.DBO.rsp_HandheldPerformance ''10/01/2009'', ''10/10/2009''')
like image 935
MartGriff Avatar asked Dec 29 '22 13:12

MartGriff


1 Answers

Even the question it's from 2009, I had the same problem en 2012!! and it was kinda difficult to find the answer....anyway just used SET NOCOUNT ON before executing the SP

if Manchester is the LinkedServer the example code with SET NOCOUNT ON should be

SELECT * 
FROM OPENQUERY([Manchester], 
      'SET NOCOUNT ON; EXEC [PilotWebApp].[DBO].rsp_HandheldPerformance ''10/01/2009'', 
      ''10/10/2009''')

And to fill the temporary table I do

SELECT *
INTO #temptable
FROM OPENQUERY([Manchester], 
          'SET NOCOUNT ON; EXEC [PilotWebApp].[DBO].rsp_HandheldPerformance ''10/01/2009'', 
          ''10/10/2009''')

https://stackoverflow.com/a/2247200/181766

like image 192
jjchiw Avatar answered Jan 15 '23 17:01

jjchiw