我正在尝试执行此查询,但我收到错误:
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中选择*是coment
答案 0 :(得分:2)
还要考虑更健壮和安全的提供者和连接字符串:'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
*/
')
答案 1 :(得分:0)
我认为你不能因为openquery / rowset接口非常有限。鉴于远程服务器是SQL服务器,您可以使用基于表的函数来提供所需的功能。否则,您可以使用远程执行存储过程或链接服务器来执行此操作。