0

このクエリを実行しようとしていますが、エラーが発生しました:

Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 208, Level 16, State 1, Line 11
Invalid object name '#test1'.

私のコード:

select * from openrowset ('SQLOLEDB','DRIVER={SQL Server};SERVER=10.12.131.58;UID=sa;PWD=desarrollo','



create table #test1
(
id int,
name1 varchar(50)
)

insert into #test1
select cliente,nomcli from opepte.dbo.clientes

select * from #test1

/*this is a example but in real query i need manipulate this information and return 
a resulset with few rows
*/


')

しかし、この他のクエリは正常に機能します。

select * from openrowset ('SQLOLEDB','DRIVER={SQL Server};SERVER=10.12.131.58;UID=sa;PWD=desarrollo','



create table #test1
(
id int,
name1 varchar(50)
)

--insert into #test1
select cliente,nomcli from opepte.dbo.clientes

--select * from #test1

/*this is a example but in real query i need manipulate this information and return 
a resulset with few rows
*/


')

注:#test1に挿入し、#test1から*を選択してください

4

2 に答える 2

2
  1. FMTONLY と NOCOUNT を使用する
  2. temp の代わりに tabled-variable を使用しないのはなぜですか? このコードを介して明示的にデータを返すため、誰も一時テーブルを再度使用することはありません。
  3. また、より堅牢で安全なプロバイダーと接続文字列を検討してください: 'SQLNCLI', 'Server=localhost;Integrated Security=SSPI;Trusted_Connection=yes;'

    select * from openrowset ('SQLOLEDB','DRIVER={SQL Server};SERVER=10.12.131.58;UID=sa;PWD=desarrollo', N'
    
    SET FMTONLY OFF
    SET NOCOUNT ON
    
    declare @q int = 1
    
    declare @test1 table
    (
    id int,
    name1 varchar(50)
    )
    
    insert into @test1
    select 1,''q''
    
    insert into @test1
    select 1,''q''
    
    select * from @test1
    
    /*this is a example but in real query i need manipulate this information and return 
    a resulset with few rows
    */
    ')
    
于 2013-03-13T05:06:18.560 に答える
0

openquery/rowset インターフェースはかなり制限されているため、できるとは思いません。リモート サーバーが SQL サーバーの場合、テーブル ベースの関数を使用して必要な機能を提供できる場合があります。それ以外の場合は、リモート実行ストアド プロシージャまたはリンク サーバーを使用してこれを行うことができます。

于 2012-11-27T20:09:36.550 に答える