LinkServer 远程执行存储过程,返回结果集

--Server:
if exists (select name from sysobjects where name='p_tmp' and type='P')
	drop proc p_tmp
go
create proc p_tmp(
	@a nvarchar(50)=N'a',
	@b nvarchar(50)=N'b'
)
--WITH ENCRYPTION
as
begin
	select @a+','+@b as c1, @b+','+@a as c2
	union all
	select @a+','+@b as c1, @b+','+@a as c2
end

--Client:
--调用方式1
DECLARE @tmp as table (c1 nvarchar(50) ,c2 nvarchar(50));
insert into @tmp exec [192.168.20.76].DProject_4D.dbo.p_tmp @a = N'xyz',@b = N'abc'
SELECT * FROM @tmp

--调用方式2:动态sql
DECLARE @tmp as table (c1 nvarchar(50) ,c2 nvarchar(50));
insert into @tmp exec sp_executesql N'exec [192.168.20.76].DProject_4D.dbo.p_tmp @str,@str2'
	, N'@str nvarchar(50), @str2 nvarchar(50)',N'中国' , N'美国'
SELECT * FROM @tmp

  附:查看最近修改的存储过程、函数

select * from sys.all_objects where type IN('P','FN','TR','IF','TF') AND modify_date>='2012-10-23' order by modify_date desc

  

posted @ 2012-10-25 14:26  庚武  Views(494)  Comments(0)    收藏  举报