可以使用Openrowset,但Openrowset不支持参数话的语句,要实现参数只能在客户端程序中把要的最终语句拼接好传入。
测试语句如下:
use
tempdb
go
create proc p_test
as
begin
select 1 as a , 2 as b , 3 as c union
select 4 as a , 5 as b , 6 as c union
select 7 as a , 8 as b , 9 as c
end
go
select * from openrowset
( 'sqlOLEDB' , 'Server=.;Trusted_Connection=yes;DataBase=tempdb' ,
'exec p_test' ) where a <> 4
go
drop proc p_test
go
create proc p_test
as
begin
select 1 as a , 2 as b , 3 as c union
select 4 as a , 5 as b , 6 as c union
select 7 as a , 8 as b , 9 as c
end
go
select * from openrowset
( 'sqlOLEDB' , 'Server=.;Trusted_Connection=yes;DataBase=tempdb' ,
'exec p_test' ) where a <> 4
go
drop proc p_test